中级农民
- 积分
- 111
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2017-9-8
- 最后登录
- 1970-1-1
|
楼主楼主!csv那道题我这样写对吗?
input : {"country,type,vendor1,vendor2,vendor3,vendor4",
"india,1,13.5,14,15,14.5"}
- string csvFormmatter(vector<string> lines){
- vector<int> wordLength;
- string res = "";
- for(string s : lines){
- string word;
- stringstream ss(s);
- int wcount = 0;
- while(getline(ss, word, ',')){
- if(wcount >= wordLength.size()){
- wordLength.push_back((int)word.length());
- } else {
- wordLength[wcount] = max(wordLength[wcount], (int)word.length());
- }
- wcount++;
- }
- }
- for(string s : lines){
- string word;
- stringstream ss(s);
- int wcount = 0;
- while (getline(ss, word, ',')) {
- res += wcount > 0 ? " " : "\n";
- int ldis = wordLength[wcount] - word.length();
- while(ldis-- > 0){
- word = " " + word;
- }
- res += word;
- wcount++;
- }
- }
- return res.substr(1);
- }
复制代码 |
|