Rotating Sentences
Rotating Sentences |
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 programwill 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 exceeding100 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 leftmostcolumn; 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 <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#define max(a, b) (a > b ? a : b)
using namespace std;
int N = 0;
string s[500];
int Max = -1;
void init_file()
{
freopen("White_GS_7.in", "r", stdin);
freopen("White_GS_7.out", "w", stdout);
}
void read_data()
{
while(getline(cin, s[N++]));
N--;
N--;
}
void work()
{
for(int i = 0; i <= N; i++)
{
int x = s[i].size();
Max = max(Max, x);
}
/*
for(int i = N; i >= 0; i--)
{
for(int j = 0; j < Max; j++)
cout << s[i][j];
}
*/
for(int j = 0; j < Max; j++)
{
for(int i = N; i >= 0; i--)
{
int x = s[i].size();
cout << (j >= x ? ' ' : s[i][j]);
}
cout << endl;
}
}
int main()
{
init_file();
read_data();
work();
return 0;
}