您的位置:首页 > 其它

Hello World for U

2014-02-19 14:54 323 查看
2012年浙江大学计算机及软件工程研究生机试真题

考察对字符串的操作。

#include <stdio.h>
#include <string.h>
char str[81];

int main(){
int len, n1, n2, n3, i, j, count;
while(scanf("%s", str) == 1){
len = strlen(str);
n1 = n3 = len / 3;
n2 = len - n1 - n3;
if(n1 == n2){
--n1; --n3;
n2 += 2;
}
count = 0;
for(i = 1; i <= n1; ++i){
for(j = 1; j <= n2; ++j)
if(j == 1) putchar(str[count++]);
else if(j == n2) putchar(str[len - count]);
else putchar(' ');
puts("");
}
//输出最后一行
for(j = 1; j <= n2; ++j)
putchar(str[count++]);
puts("");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: