寒假刷题之5——竹简文
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.
Input
Rene Decartes once said,
"I think, therefore I am."
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,
.
"
感觉好水啊这题,题目很容易就看懂了,为了搞清楚输入输出细节我借助了google翻译,结果"I think, therefore I am."这句名言变成了刘若英说的,让人捧腹。。。
wa了几次,老会把空格打成a,定义ch数组时老是无法正常定义,遇到a条件输出空格也不行,不知道是错误出在哪里。。
#include<stdio.h>
int main()
{
int i = 0, j = 0, maxj = 0, maxi;
char ch[100][100], temp;
int row[100] = {0};
for (;(temp = getchar()) != EOF;){
if (temp == '\n'){
i ++;
j = 0;
}
else if (temp != '\t'){
ch[i][j++] = temp;
if (maxj < j)
maxj = j;
row[i] = j;
}
}
maxi = i - 1;
for (j = 0; j < maxj; j ++){
for (i = maxi; i >= 0; i --)
printf("%c", j < row[i] ? ch[i][j]: ' ');
printf("\n");
}
return 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.
Input
Rene Decartes once said,
"I think, therefore I am."
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,
.
"
感觉好水啊这题,题目很容易就看懂了,为了搞清楚输入输出细节我借助了google翻译,结果"I think, therefore I am."这句名言变成了刘若英说的,让人捧腹。。。
wa了几次,老会把空格打成a,定义ch数组时老是无法正常定义,遇到a条件输出空格也不行,不知道是错误出在哪里。。
#include<stdio.h>
int main()
{
int i = 0, j = 0, maxj = 0, maxi;
char ch[100][100], temp;
int row[100] = {0};
for (;(temp = getchar()) != EOF;){
if (temp == '\n'){
i ++;
j = 0;
}
else if (temp != '\t'){
ch[i][j++] = temp;
if (maxj < j)
maxj = j;
row[i] = j;
}
}
maxi = i - 1;
for (j = 0; j < maxj; j ++){
for (i = maxi; i >= 0; i --)
printf("%c", j < row[i] ? ch[i][j]: ' ');
printf("\n");
}
return 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.
Input
Rene Decartes once said, "I think, therefore I am."
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, . "
wa了几次,老会把空格打成a,定义ch数组时老是无法正常定义,遇到a条件输出空格也不行,不知道是错误出在哪里。。
#include<stdio.h> int main() { int i = 0, j = 0, maxj = 0, maxi; char ch[100][100], temp; int row[100] = {0}; for (;(temp = getchar()) != EOF;){ if (temp == '\n'){ i ++; j = 0; } else if (temp != '\t'){ ch[i][j++] = temp; if (maxj < j) maxj = j; row[i] = j; } } maxi = i - 1; for (j = 0; j < maxj; j ++){ for (i = maxi; i >= 0; i --) printf("%c", j < row[i] ? ch[i][j]: ' '); printf("\n"); } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步