九度:1464<Hello World For U><排版>
2014-03-06 08:58
621 查看
// 浙大12机试 // Hello world for U // 排版 // #include <stdio.h> #include <string.h> int main() { #ifdef ONLINE_JUDGE #else freopen("E:\\in.txt" , "r", stdin); freopen("E:\\out.txt", "w", stdout); #endif char s[100]; while(scanf("%s", s) != EOF) { int n = strlen(s); if( n<5 || n>80) { break; } char map[100][100]; memset(map, ' ', sizeof(map)); // 之后没有填充区域为空格,所以应该以' '初始化, // 而不是memset(map, 0, sizeof(map)); // 和正确的代码的结果输出到txt,图形所占空间完全相同, // 但就是不正确。这个错误是隐形的呢? int n1=0,n2=0,n3=0; n2 = (n+2)/3 > 3 ? (n+2)/3 : 3; if((n-n2)%2 == 0) { n1=n3=(n+2-n2)/2; } else { n2++; n1=n3=(n+2-n2)/2; } while(n2<n1) { n2+=2; n1--; n3--; } //printf("n1=%d n2=%d n3=%d\n", n1, n2,n3); //print int i=0, j=0, k=0; while(i<n1) { map[i++][j] = s[k++]; } i=i-1; j=j+1; while(j<n2) { map[i][j++]=s[k++]; } i=i-1; j=j-1; while(i>=0) { map[i--][j]=s[k++]; } if(k != n) { printf("Error\n"); } for(i=0; i<n1; i++) { for(j=0; j<n2; j++) { printf("%c", map[i][j]); } printf("\n"); } } return 0; }
相关文章推荐
- <Linux+Qt> Qt基本Hello,World解释
- Spark实现的hello world<转>
- 九度:1011<A+B for Metrics>
- <script type="text/javascript">alert("hello world");</script>
- COBOL语言编写<hello world>
- 九度考研真题 浙大 2012-1浙大1464:Hello World for U
- 【LaTeX排版】LaTeX论文排版<三>
- <备份>0926网络配置与while for until
- 九度:1014<排序>
- 九度:1018<Hash>
- UESTC_全都是秋实大哥 2015 UESTC Training for Search Algorithm & String<Problem J>
- 九度:1031<3n+1>
- 错误集_ nib文件加载,Unknown class <XXClass> in Interface Builder file.,Undefined symbolsfor architecture
- <github for windows(win10)客户端安装教程>
- 写了一个hello.py,运行出错,提示 File "<stdin>" , line 1
- <Python for Kids>读书笔记
- [Angular 2] More on *ngFor, @ContentChildren & QueryList<>
- Unbalanced calls to begin/end appearance transitions for <IDOOrderHomeViewController: 0x8da2960>.
- startActivityforResult传递List<Object>参数错误问题
- 【LaTeX排版】LaTeX纸排版<两>