https://vjudge.net/contest/185301#problem/A
学习了好多新函数,只要关注每个单词的列宽就行了。自动切分太厉害了吧~
1 #include<iomanip> 2 #include<stdio.h> 3 #include<string.h> 4 #include<math.h> 5 #include<iostream> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<queue> 9 #include<vector> 10 #include<string> 11 #include<set> 12 #include<cctype> 13 #include<sstream> 14 #define mem(a) memset(a,0,sizeof(a)) 15 #define LL long long 16 #define ull unsigned long long 17 #define inf 0x3f3f3f3f 18 using namespace std; 19 const int N=2e4+10; 20 int n,m; 21 int a[N],b[N],c[N][N]; 22 vector<string>s[1010]; 23 24 int main() 25 { 26 string line,tem; 27 int v=0,c[1005],u=0; 28 mem(c); 29 while(getline(cin,line)) 30 { 31 istringstream ans(line); //自动切分|空格|读入 32 while(ans>>tem) 33 { 34 c[v]=max(c[v],(int)tem.size()); 35 s[u].push_back(tem); 36 v++; 37 } 38 v=0,u++; 39 } 40 cout<<setiosflags(ios::left);//左对齐 41 for(int i=0;i<u;i++) 42 { 43 int j; 44 for(j=0;j<s[i].size()-1;j++) 45 {cout <<setw(c[j]+1)<<s[i][j];} // 设置s[i][j]域宽 46 47 cout<<s[i][j]<<endl; 48 } 49 50 return 0; 51 }