您的位置:首页 > 其它

UVA490 Rotating Sentences 字符串输入输出处理

2018-03-27 20:17 771 查看
In “Rotating Sentences,” you are asked to rotate a series of input sentences 90 degrees clockwise. Soinstead of displaying the input sentences from left to right and top to bottom, your program will displaythem from top to bottom and right to left.InputAs input to your program, you will be given a maximum of 100 sentences, each not exceeding 100characters long. Legal characters include: newline, space, any punctuation characters, digits, and lowercase or upper case English letters. (NOTE: Tabs are not legal characters.)OutputThe 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 InputRene Decartes once said,"I think, therefore I am."Sample Output"RIentehiDnekc,arttheesreofnocreesIaiadm,."题意简述:  输入若干行字符串,将其旋转90度后输出。

#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[222][222]={0};
int maxx=0;
int i=0;
while(gets(a[i])!=NULL)
{
if(strlen(a[i])>maxx)maxx=strlen(a[i]);
i++;

}
// cout<<i;
/* for(int w=0;w<50;w++)
{
for(int e=0;e<50;e++)cout<<a[w][e];
cout<<endl;
}*/
// cout<<a[0]<<endl<<a[1];

for(int j=0;j<maxx;j++)
for(int k=i-1;k>=0;k--)
{
if(a[k][j]==0)cout<<" ";
else cout<<a[k][j];
if(!k)cout<<endl;
}

return 0;
}如果是二位数组a[10][10] , a[0]指的是第一行一整行;
以后读字符串可以这样写:
while(gets(a[i])!=NULL)

In “Rotating Sentences,” you are asked to rotate a series of input sentences 90 degrees clockwise. Soinstead of displaying the input sentences from left to right and top to bottom, your program will displaythem from top to bottom and right to left.InputAs input to your program, you will be given a maximum of 100 sentences, each not exceeding 100characters long. Legal characters include: newline, space, any punctuation characters, digits, and lowercase or upper case English letters. (NOTE: Tabs are not legal characters.)OutputThe 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 InputRene Decartes once said,"I think, therefore I am."Sample Output"RIentehiDnekc,arttheesreofnocreesIaiadm,."

问题链接:UVA490 Rotating Sentences。题意简述:  输入若干行字符串,将其旋转90度后输出。
问题分析:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: