UVa - 490 - Rotating Sentences (AC)


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,
.
"
题目的意思是输入不超过100行的字符串,每个字符串不超过一百个字符,这些字符串中包含空格,各种符号标点,以及大小写字母,然后将这些字符串顺时针选择90度输出,即:第一行成为最后一列, 最后一行成为最左一列
 
注:因为各个字符串长度不一致,所以一定要注意空格的输出
 
#include <stdio.h>
#include <string.h>
#define MAXM 100+10
#define MAXN 100+10
char buf[MAXM][MAXN];
int main()
{
	int i, j, k, x, len;
	char ch;
	i =0;
	j = 0;
	len = 0;
	memset(buf, 0, sizeof(buf));
	while((ch = getchar())!=EOF)
	{
		if(ch == 10) //ASCII值为10是换行符,表示一个字符串输入结束
		{
			buf[i][j] = '\0';
			if(len < j)
				len = j;
			i++;
			j=0;
			continue;
		}
		buf[i][j++] = ch;

	}
	for(x = 0; x < len; x++)
	{
		for(k = i-1; k >= 0; k--) //初始值为i-1是跳出while循环i多加了1
		{
		//putchar(buf[k][x]); 只是这样输出会发生wrong answer,我刚开始范的错误
		//这是因为每一行的字符长度不同,而,len为最长的字符串长度,所以有的buf[k][x]为0(null),
		//putchar(null)这个就会什么都不输出, 所以此处必须用if...else 判断字符是否为空,从而正确输出空格
			if(buf[k][x])
				printf("%c", buf[k][x]);
			else
				putchar(' ');
		}
		printf("\n");
	}
	return 0;
}


 
 
 
 
 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值