标签:检查 大写 ret == printf chat std amp gets
1 #include<stdio.h> 2 #include<string.h> 3 4 char b[1005]; 5 int judge(int x) 6 { 7 return !((b[x]>=‘A‘ && b[x]<=‘Z‘) || (b[x]>=‘a‘ && b[x]<=‘z‘) || (b[x]>=‘0‘ && b[x]<=‘9‘)); 8 } 9 10 11 int main(void) 12 { 13 int i,j; 14 int n,c; 15 char a[1005]; 16 17 scanf("%d",&n); 18 getchar(); 19 20 while(n--) 21 { 22 gets(a); 23 puts(a); 24 printf("AI: "); 25 c = i = 0; 26 27 for(i=0; a[i]; i++) 28 { 29 if(a[i] == ‘ ‘) //把所有空格窦归为一个 30 { 31 while(a[i] == ‘ ‘) 32 { 33 i++; 34 } 35 b[c++] = ‘ ‘; 36 i--; 37 } 38 else if(a[i] == ‘?‘) 39 { 40 b[c++] = ‘!‘; 41 } 42 else if(a[i]>=‘A‘ && a[i]<=‘Z‘ && a[i]!=‘I‘) 43 { 44 b[c++] = a[i]+32; 45 } 46 else 47 { 48 b[c++] = a[i]; 49 } 50 } 51 52 for(i=0; i<c; i++) //strstr返回的是地址! 53 { 54 if(i==0 && b[i]==‘ ‘) continue; 55 if((i==0 || judge(i-1)) && strstr(b+i,"could you")==&b[i] && (i+9==c || judge(i+9))) //i使用来检查是否在首尾独立 56 { //judge检查是否在句中独立 57 printf("I could"); 58 i+=8; 59 } 60 else if((i==0 || judge(i-1)) && strstr(b+i,"can you")==&b[i] && (i+7==c || judge(i+7))) 61 { 62 printf("I can"); 63 i+=6; 64 } 65 else if((i==0 || judge(i-1)) && b[i]==‘m‘ && b[i+1]==‘e‘ && (i+2==c || judge(i+2))) 66 { 67 printf("you"); 68 i++; 69 } 70 else if((i==0 || judge(i-1)) && b[i]==‘I‘ && (i+1==c || judge(i+1))) 71 { 72 printf("you"); 73 } 74 else if(b[i]==‘ ‘) 75 { 76 if(i==c-1) continue; //结尾空格 77 if(!judge(i+1))//如果空格后一个是数字或者字母 直接过滤掉标点 78 { 79 printf(" "); 80 } 81 } 82 else 83 { 84 printf("%c",b[i]); 85 } 86 } 87 printf("\n"); 88 } 89 90 return 0; 91 }
标签:检查 大写 ret == printf chat std amp gets
原文地址:https://www.cnblogs.com/ZhengLijie/p/12491443.html