UVaOJ 490 Rotating Sentences
来源:互联网 发布:中科大苏州软件学院 编辑:程序博客网 时间:2024/05/29 12:56
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span><pre name="code" class="cpp">#include <stdio.h>#include <string.h>#include <ctype.h>char d[110][110];int main(){ freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); int cnt = 0,maxlen = 0; while(fgets(d[cnt++],110,stdin)!=NULL); for(int t1 = 0 ;t1<cnt;t1++) for(int t2 = 0;t2<110;t2++){ if(d[t1][t2] == '\n') d[t1][t2]='\0'; } for(int pp = 0 ; pp<cnt; pp++) { if(strlen(d[pp])>maxlen) maxlen = strlen(d[pp]); } for(int k = 0; k<maxlen; k++) { for(int t = cnt-2; t>=0; t--) { if(d[t][k]!='\0') printf("%c",d[t][k]); else printf(" "); } printf("\n"); } return 0;}
1、fgets会将每一行最后一个换行符'\n'读到数组中,所以读完后,要将每行换行符置为'\0'
2、最后输出时,要从cnt-2开始,作用是去掉最后一行结束行。
下面是用gets函数AC的代码,不过fgets比gets更安全,但在这个题上,用gets貌似更方便。
#include <stdio.h>#include <string.h>#include <ctype.h>char d[110][110];int main(){ //freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int cnt = 0; while(gets(d[cnt++])); int max = 0; for(int p=0;p<cnt;p++) { if(strlen(d[p])>max)max=strlen(d[p]); } for(int k = 0; k<max; k++) { for(int j = cnt-2;j>=0;j--){ if(d[j][k]!='\0')printf("%c",d[j][k]);else printf(" "); } printf("\n"); } return 0;}
0 0
- uvaoj 490 - Rotating Sentences
- UVaOJ 490 - Rotating Sentences
- UVaOJ 490 Rotating Sentences
- UVaOJ 490 - Rotating Sentences
- UVaOJ 490 Rotating Sentences
- 490 - Rotating Sentences
- Uva 490 Rotating Sentences
- UVa 490 - Rotating Sentences
- UVA-490-Rotating Sentences
- 490 - Rotating Sentences
- 490 - Rotating Sentences
- UVa 490 - Rotating Sentences
- UVA 490 - Rotating Sentences
- UVa 490 - Rotating Sentences
- 490 - Rotating Sentences
- 490 - Rotating Sentences
- UVa:490 - Rotating Sentences
- 490 - Rotating Sentences
- 基础知识再复习(1):x=x&(x-1)
- 【ImageMagick 】-ImageMagick的安装和使用
- 第四周项目四 指向学生类的指针
- 几种常见的NoSQL数据库比较
- Can’t connect to local MySQL server through socket 解决办法
- UVaOJ 490 Rotating Sentences
- android中的sqlite数据库
- Java JDBC和MySQL
- virtualBox虚拟机的一些配置
- 并查集入门
- ORACLE_基础十二(Profiles)
- BUPT OJ 147. Substring
- poj 3616 Milking Time DP
- a new client --- using httpclient or curl or requests