uva 1593 Alignment of Code
2017-07-27 14:16
302 查看
题目:Alignment of Code
题意:给定一些代码片段,按给定的个时对其输出。
代码:#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
string before[1005];
string a[1005][85];
int cnt[1005]= {0};
int Max=0;
void change(int x) {
before[x]+=" ";
for(int i=0; i<before[x].size(); i++) {
if(before[x][i]!=' ') {
a[x][cnt[x]]+=before[x][i];
} else if(i!=0&&before[x][i-1]!=' ') {
cnt[x]++;
}
}
Max=max(Max,cnt[x]);
}
int main() {
int T=0;
while(getline(cin,before[T++]));
for(int i=0; i<T; i++) {
change(i);
}
T--;
int longest[85]= {0};
for(int i=0; i<T; i++) {
for(int j=0; j<Max; j++) {
int x=a[i][j].size();
longest[j]=max(longest[j],x);
}
}
for(int i=0; i<T; i++) {
for(int j=0; j<cnt[i]; j++) {
cout<<a[i][j];
if(j!=cnt[i]-1) {
for(int k=a[i][j].size(); k<=longest[j]; k++) {
cout<<' ';
}
}
}
cout<<endl;
}
return 0;
}
题意:给定一些代码片段,按给定的个时对其输出。
代码:#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
string before[1005];
string a[1005][85];
int cnt[1005]= {0};
int Max=0;
void change(int x) {
before[x]+=" ";
for(int i=0; i<before[x].size(); i++) {
if(before[x][i]!=' ') {
a[x][cnt[x]]+=before[x][i];
} else if(i!=0&&before[x][i-1]!=' ') {
cnt[x]++;
}
}
Max=max(Max,cnt[x]);
}
int main() {
int T=0;
while(getline(cin,before[T++]));
for(int i=0; i<T; i++) {
change(i);
}
T--;
int longest[85]= {0};
for(int i=0; i<T; i++) {
for(int j=0; j<Max; j++) {
int x=a[i][j].size();
longest[j]=max(longest[j],x);
}
}
for(int i=0; i<T; i++) {
for(int j=0; j<cnt[i]; j++) {
cout<<a[i][j];
if(j!=cnt[i]-1) {
for(int k=a[i][j].size(); k<=longest[j]; k++) {
cout<<' ';
}
}
}
cout<<endl;
}
return 0;
}
相关文章推荐
- UVA1593 - Alignment of Code(这题确实看不太懂)
- UVa 1593 (水题 STL) Alignment of Code
- UVA 1593 Alignment of Code
- UVA 1593 Alignment of Code
- [刷题]算法竞赛入门经典(第2版) 5-1/UVa1593 - Alignment of Code
- Uva1593 - Alignment of Code
- UVA - 1593 Alignment of Code
- UVa 1593 - Alignment of Code
- UVA- 1593 - Alignment of Code
- UVA 1593(p135)----Alignment of Code
- UVa1593 Alignment of Code
- UVa 1593 Alignment of Code
- UVa 1593 - Alignment of Code
- UVA - 1593 Alignment of Code(熟练c++操作)
- UVa 1593 - Alignment of Code
- UVa 1593 Alignment of Code
- UVa 1593 Alignment of Code(字符串)
- Uva1593——Alignment of Code
- UVa 1593 - Alignment of Code
- Uva - 1593 - Alignment of Code