TopCoder High School SRM 15 Level one - 250 pt - Numbers Line editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm15
TopCoder High School SRM 15 Level one - 250 pt - Numbers Line solution:
#include <iostream> #include <sstream> #include <algorithm> using namespace std; class NumbersLine { public: int getLeast(string s, int n) { int ans=-1, a, arr[55]={0}, i=0; istringstream ss(s); while(ss>>a) arr[i]=a, i++; sort(arr, arr+i); for(int j=0; j<i; j++) if(arr[j]>n) {ans=arr[j]; break;} return ans; } };
note: for istringstream of <sstream> C++:
1 - http://www.cplusplus.com/reference/sstream/istringstream/
2 - http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=standardTemplateLibrary
3 - http://community.topcoder.com/tc?module=Static&d1=features&d2=112106
No comments:
Post a Comment