24h購物| | PChome| 登入
2012-05-03 18:29:56| 人氣3,481| 回應0 | 上一篇 | 下一篇

[UVA][Normal] 490 - Rotating Sentences

推薦 0 收藏 0 轉貼0 訂閱站台


 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,
.
"

殺死人不償命的空白處理, 要補滿 n*m 的方格

#include <stdio.h>
#include <string.h>

int main() {
    char s[105][105], c[105][105];
    int n = 0, m = 0, i, j;
    while(gets(s[n]))
        n++;
    memset(c, ' ', sizeof(c));
    for(i = 0; i < n; i++) {
        for(j = 0; s[i][j]; j++)
            c[j][n-i-1] = s[i][j];
        m = m > j ? m : j;
    }
    for(i = 0; i < m; i++) {
        c[i][n] = '\0';
        puts(c[i]);
    }
    return 0;
}

台長: Morris
人氣(3,481) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][zkw式] 100 - The 3n + 1 problem
此分類上一篇:[UVA][EASY] 445 - Marvelous Mazes

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文