練習中
C++の練習がてらに簡単なTopCoderの問題を解いてみる。
SRM 255 DIV2 250
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <sstream> using namespace std; class SequenceOfNumbers{ public: vector <string> rearrange(vector <string> sequence){ vector <int> numbers; vector <string> ans; vector <string>::iterator strIt = sequence.begin(); while (strIt != sequence.end()){ string str = *strIt; numbers.push_back(atoi(str.data())); ++ strIt; } sort(numbers.begin(), numbers.end()); vector <int>::iterator intIt = numbers.begin(); while (intIt != numbers.end()){ ostringstream s; s << *intIt; ans.push_back(s.str()); ++ intIt; } return ans; } };
stringをintに変換して並び替え、そしてまたintをstringに変換するというだけの問題。
まあこんな感じでいいのかな。