UVaOJ 490

来源:互联网 发布:网络arp检测工具 编辑:程序博客网 时间:2024/05/15 07:21

UVaOJ 490 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 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

“R
Ie
n
te
h
iD
ne
kc
,a
r
tt
he
es
r
eo
fn
oc
re
e
s
Ia
i
ad
m,
.

注意字符串中不够长的要以空格输出替代。

#include <stdio.h>#include <string.h>#define LOCAL#define MAXN 100 + 10char s[MAXN][MAXN];int main(void){    #ifdef LOCAL    freopen("490.in", "rb", stdin);    freopen("490.out", "wb",stdout);    #endif // LOCAL    int count = 0, maxn = 0, i, j;    memset(s, 0, sizeof(s));    //初始化字符串 !!!重要    while((gets(s[count])) != NULL)    {        maxn = maxn >= strlen(s[count]) ? maxn : strlen(s[count]);        count ++;    }    for(i = 0; i < maxn; i ++)    {        for(j = count - 1; j >= 0; j --)        {            if(s[j][i] == 0)                putchar(' ');            else                putchar(s[j][i]);        }        putchar('\n');    }    return 0;}
0 0
原创粉丝点击