Rotating Sentences UVA - 490 (模拟)

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
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.)
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
#include
#include
#include
using namespace std;
typedef long long ll;
string s[1005];
int len[1005];
int main()
{
	ios::sync_with_stdio(false);
	cout.tie(NULL);
	int k=0,maxc=0;
	while(getline(cin,s[k]))
	{
		len[k]=s[k].size();
		maxc=max(maxc,len[k]);
		k++;
	}
	for(int j=0;j<maxc;j++)
	{
		for(int i=k-1;i>=0;i--)
		{
			if(j>=len[i])
				cout<<" ";
			else
				cout<<s[i][j];
		}
		cout<<endl;
	}
	return 0;
 } 

你可能感兴趣的:(模拟)