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.
Input
As 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.)
Output
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
"R
Ie
n
te
h
iD
ne
kc
,a
r
tt
he
es
r
eo
fn
oc
re
e
s
Ia
i
ad
m,
.
"
题意简述:
输入若干行字符串,将其旋转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.
Input
As 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.)
Output
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
"R
Ie
n
te
h
iD
ne
kc
,a
r
tt
he
es
r
eo
fn
oc
re
e
s
Ia
i
ad
m,
.
"
问题链接:UVA490 Rotating Sentences。
题意简述:
输入若干行字符串,将其旋转90度后输出。
问题分析: