UVA:490 - Rotating Sentences

来源:互联网 发布:it 项目 编辑:程序博客网 时间:2024/06/11 21:10

In ``Rotating Sentences,'' you are asked to rotate a series of input sentences 90 degrees clockwise. So instead of displaying the input sentences from left to right and top to bottom, your program will display them from top to bottom and right to left.

Input and Output

As input to your program, you will be given a maximum of 100 sentences, each not exceeding 100 characters long. Legal characters include: newline, space, any punctuation characters, digits, and lower case or upper case English letters. (NOTE: Tabs are not legal characters.)

The output of the program should have the last sentence printed out vertically in the leftmost column; the first sentence of the input would subsequently end up at the rightmost column.

Sample Input

Rene Decartes once said,"I think, therefore I am."

Sample Output

"RIe nteh iDnekc,a rttheesreofnocree sIa iadm,."

这题千万注意要初始化数组!!就因为忘记清零数组我折腾了一个下午大哭

#include <cstdlib>#include <iostream>#include <string.h>using namespace std;const int MAX=110;int main(int argc, char *argv[]){    //system("color 0a");    char input[MAX][MAX];    memset(input,0,sizeof(input));    int n=0,max=0;    while( cin.getline(input[n],MAX) )    {           int t=strlen(input[n]);           if( t>max )max=t;           n++;    }    for( int j=0 ; j<max ; ++j )    {         for( int i=n-1 ; i>=0 ; --i )         {              if( input[i][j]==0 )              cout<<' ';              else              cout<<input[i][j];         }         cout<<endl;    }    //system("PAUSE");    return 0;}


原创粉丝点击