UVA_490:Rotating Sentences

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

Language:C++ 4.8.2

#include<stdio.h>
#include<string.h>
#define MAXN 100+10
char str[MAXN][MAXN];
int main(void)
{
	memset(str, 0, sizeof(str));
	int count = 0;
	while(fgets(str[count], MAXN, stdin) != NULL)
		count++;
	// 程序执行到这里,count代表读入句子的个数
	int max_length = 0;
	for(int i = 0; i < count; i++)
	{
		int length = strlen(str[i]);
		if(max_length < length)
			max_length = length;
	}

	max_length--; // 没有这一行的话,程序WA,这是由fgets的特性决定的,因为在我们开的空间足够大的情况下,字符串会以‘\n‘和‘\0‘结尾。
	int row, col;
	for(row = 0; row < max_length; row++)
	{
		for(col = 0; col < count; col++)
		{
			int ch = str[count-1-col][row];
			if(ch == ‘\0‘ || ch == ‘\n‘)
				putchar(‘ ‘);
			else
				putchar(ch);
		}

		putchar(‘\n‘); // 注意:如果该行前加语句if(row != max_length -1),也会WA,个中缘由自己体会吧。
	}
	return 0;
}

PS:开始理解错题意了,以为每行的输入字符个数是递增的,导致一直A不了。
时间: 2024-11-21 05:26:46

UVA_490:Rotating Sentences的相关文章

490 - 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 program will display them from top to bo

UVA490 Rotating Sentences

问题链接:UVA490 Rotating Sentences. 题意简述:输入若干行字符串,将其旋转90度后输出. 问题分析:需要一个二维数组存储输入的字符串,好在规模不大. 程序说明:封装了函数mygets()(函数gets()在新标准中,被建议不要使用,作用就自己做一个),其他都是套路. AC的C语言程序如下: /* UVA490 Rotating Sentences */ #include <stdio.h> #include <memory.h> #define MAXN

UVa 490 - Rotating Sentences

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=431 题目:将输入的句子,反转90度后输出. 思路:第i行字符串旋转90度后,其字符为每一行的第i个字符. 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio>

UVa--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 program will display them from top to bot

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

Hashmat the Brave Warrior

Hashmat the Brave Warrior XX自己有士兵a人, 敌军有士兵b人,自己的士兵永远比敌军少, 求对方比自己多多少人.       (虽说要从头刷,但是这样的还是太水了吧 2333333 喜闻乐见的错了因为2^32爆了int...These two numbers in each line denotes the number of soldiers in Hashmat's army and his opponent's army or vice versa 1 #incl

Rotating clockwise inward matrix

Problem: Write a program to: 1) wait for the user to input a positive integer N, and 2) output a NxN matrix on the screen with numbers 1 to N, rotating clockwise inward. For example, if N = 4, then the output should be: 1 2 3 4 12 13 14 5 11 16 15 6

Description has only two Sentences(欧拉定理 +快速幂+分解质因数)

Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 124 Accepted Submission(s): 55   Problem Description an = X*an-1 + Y and Y mod (X-1) = 0.Your task is to calculat

poj 3335 Rotating Scoreboard(半平面交)

Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 2550 Description This year, ACM/ICPC World finals will be held in a hall in form of a simple polygon. The coaches and spectators are seated along the ed