UVA1593

来源:互联网 发布:知思索的意思 编辑:程序博客网 时间:2024/05/19 02:16
补题计划——利用本学期和寒假补完白书上的例题和课后题,寒假回来专心刷训练指南。

题目大意:输入若干单词,将他们对齐后输出,并且要求每一行末尾不得有空格。

#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <sstream>using namespace std;int main(){    string str[1000][100];    string Lbuf,Sbuf;    int maxlen[180]={0};    int len=0,maxl=0,maxc=0;    int i=0,j=0;    while(getline(cin,Lbuf)){        j=0;        stringstream strin(Lbuf);        while(strin>>Sbuf){            len=Sbuf.length();            maxlen[j]=len>maxlen[j]?len:maxlen[j];            str[i][j]=Sbuf;            j++;        }        maxc=maxc>j?maxc:j;        i++;    }    maxl=i;    for(i=0;i<maxl;i++){        for(j=0;j<maxc;j++){            if(str[i][j].length()==0)                break;            cout<<str[i][j];            if(str[i][j+1].length()!=0){                for(int m=str[i][j].length();m<maxlen[j];m++){                    cout<<" ";                }                cout<<" ";            }        }        cout<<endl;    }    return 0;}

0 0