ACM Getting Started
熟悉刷题的基本输入输出操作和 刷水题的蒻鲫故事
吃了没文化的亏 简单题看题意半天 实在不行看中英文对照了 就只看输入输出猜猜题意 菜啊
494 - Kindergarten Counting Game
Everybody sit down in a circle. Ok. Listen to me carefully. “Woooooo, you scwewy wabbit!” Now, could someone tell me how many words I just said? Input Input to your program will consist of a series of lines, each line containing multiple words (at least one). A “word” is defined as a consecutive sequence of letters (upper and/or lower case). Output Your program should output a word count for each line of input. Each word count should be printed on a separate line. Sample Input Meep Meep! I tot I taw a putty tat. I did! I did! I did taw a putty tat. Shsssssssssh ... I am hunting wab。。。。
题目大意 输入一句话 输出里面的单词数 题解遇字符标记下 下一个不是字符且有标记时 计数器+1
1 #include<stdio.h> 2 #include<string.h> 3 4 int main(){ 5 char s[100010]; 6 while(gets(s)) 7 { 8 int m=strlen(s);int i=0;int ans=0; 9 int flag = 0; 10 for(;i<m;i++){ 11 if(!flag) 12 if(s[i]<='z' && s[i] >= 'A') 13 flag=1; 14 15 if(flag && (s[i]>'z'||(s[i]<'A'))) 16 {ans++;flag=0;} 17 } 18 printf("%d ",ans); 19 } 20 return 0; 21 }
Uva414Machined Surfaces
讲道理啊 做起来就是阅读理解 水题无疑
题意 输入一个 n 再输入 n 行字符串(左右为X 中间为空格 注意),问最多能移动几格
移动就是左边的X从中间空位移到最右边的第一个X
把最小空格数记录下 每行减去最小空格数相加即可 代码如下 至于fgets 还是gets 都随便
用fgets(s,27,stdin) 只能读入最大 26 个字符的字符串 WA两发 活该
#include<string.h>//uva414 //Machined Surfaces //memset(a,0,sizeof(a)); #include<stdio.h> int main(){ int i,j,n,a[20];char s[26]; while(scanf("%d%*c",&n) && n){ int min =100,ans =0; for( i=0;i< n;i++) { //getchar(); int cnt = 0; fgets(s,27,stdin); int len= strlen(s); for( j=0; j< len; j++){ if(s[j] == 'X') cnt++; } a[i] = 25-cnt; if(a[i] < min) min = a[i]; ans += a[i]; } printf("%d ",ans-min*n ); } return 0; } #include<stdio.h> int main(){ int i,j,n,a[20];char s[26]; while(scanf("%d",&n) && n){ int min =100,ans =0;getchar(); for( i=0;i< n;i++) { int cnt = 0; fgets(s,27,stdin); int len= strlen(s); for( j=0; j< len; j++){ if(s[j] == 'X') cnt++; } a[i] = 25-cnt; if(a[i] < min) min = a[i]; ans += a[i]; } printf("%d ",ans-min*n ); } return 0; } #include<stdio.h> int main(){ int i,j,n,a[20];char s[26]; while(scanf("%d%*c",&n) && n){ int min =100,ans =0; for( i=0;i< n;i++) { int cnt = 0; gets(s); int len= strlen(s); for( j=0; j< len; j++){ if(s[j] == 'X') cnt++; } a[i] = 25-cnt; if(a[i] < min) min = a[i]; ans += a[i]; } printf("%d ",ans-min*n ); } return 0; } #include<stdio.h> int main(){ int i,j,n,a[20];char s[26]; while(scanf("%d",&n) && n){ int min =100,ans =0; for( i=0;i< n;i++) { int cnt = 0; getchar();fgets(s,26,stdin); int len= strlen(s); for( j=0; j< len; j++){ if(s[j] == 'X') cnt++; } a[i] = 25-cnt; if(a[i] < min) min = a[i]; ans += a[i]; } printf("%d ",ans-min*n ); } return 0; }
uva490 “Rotating Sentences,”
优秀的字符串水题
题意 输入多行句子 将句子按从后到前竖着输出
定义一个二维数组 输入计数 直到NULL 如果用 gets(s[tot]) 的话就没啥
你用fget(s[tot],110,stdin)就得注意 它最后会多输出一个 没了 代码如下
PE 到想哭 AC就在眼前 那么近却又那么远
#include <stdio.h>//uva490 Rotating Sentences #include <string.h> char s[110][110]; int main(){ int i =0,j,cnt =0,len,minu=0 ; int tot = 0 ; while ( gets(s[tot]) != NULL){// ~scanf("%[^ ]",&s[tot]) ){ len = strlen(s[tot]); //if(len == 0) break; if(len > minu) minu = len; i++;cnt++; //printf("%s ", s[tot]); tot++; } for( i= 0;i< minu ;i++) { for(int j= tot-1;j >= 0; j--) { len = strlen(s[j]); if( i >= len ) printf(" "); else printf("%c", s[j][i]); } printf(" "); } return 0; } #include <iostream> #include <stdio.h> #include <string.h> char s[110][110]; int main(){ int i =0,j,cnt =0,len,minu=0 ; int tot = 0 ; while ( fgets(s[tot],110,stdin) != NULL) { len = strlen(s[tot]); if(len > minu) minu = len; if(s[tot][len-1] == ' ') s[tot][len-1] = '