SRM 164 DIV2 Level One - 右揃え
テキストのフォーマット問題。
全ての長さが同じになるように右揃えにしなさいと。
#include <string> #include <vector> #include <sstream> #include <iomanip> #include <algorithm> using namespace std; #define foreach(bind, item) \ for (typeof ((item).begin()) bind = (item).begin(), __ie = (item).end() ;\ bind != __ie ; \ bind++) class Justifier { public: static vector<string> justify(vector<string> textln) { vector<string> buffer; int max_len = 0; foreach(s, textln) max_len = max((int) (*s).length(), max_len); foreach(s, textln) { stringstream ss; ss << setw(max_len) << setfill(' ') << *s; buffer.push_back(ss.str()); } return buffer; } };
破壊が気持ち悪くなってきたので、速度に問題が無ければ元のデータは壊さないように行こう。
英語メモ
- justify
- 正当化する、揃える
- right justify
- 右揃え