百度之星程序设计大赛 E题 题目意思很简单 可是却坑了我无数次,WA到死啊!
View Code
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<ctype.h> 5 6 int main() 7 { 8 int i,j,ncases,J=0,C=0; 9 int k,len,ok; 10 char s[201]; 11 12 scanf("%s",s); 13 len = strlen(s); 14 for(i=0; i<len; i++) 15 { 16 if(isupper(s[i])) 17 { 18 J = 1; 19 if(i == 0) 20 { 21 C=1; 22 break; 23 } 24 } 25 if(s[i]=='_') 26 { 27 C = 1; 28 if(i==0||s[i+1]=='\0'||s[i+1]=='_') 29 { 30 J = 1; 31 break; 32 } 33 } 34 } 35 if(J == 1&&C == 1) 36 printf("Error!\n"); 37 if(J==0 && C==0) 38 printf("%s\n",s); 39 if(J==1&&C==0) 40 { 41 k = 0; 42 for(j=0; s[j]!='\0'; j++) 43 { 44 if(isupper(s[j])) 45 { 46 47 printf("_%c",tolower(s[j])); 48 } 49 else 50 { 51 printf("%c",s[j]); 52 } 53 } 54 printf("\n"); 55 } 56 if(C==1&&J==0) 57 { 58 k = 0; 59 for(j=0,ok=0; s[j]!='\0'; j++) 60 { 61 if(s[j] == '_') 62 { 63 ok = 1; 64 continue; 65 } 66 if(islower(s[j])&&ok==1) 67 { 68 printf("%c",toupper(s[j])); 69 ok = 0; 70 } 71 else 72 { 73 printf("%c",s[j]); 74 } 75 } 76 printf("\n"); 77 } 78 //system("pause"); 79 return 0; 80 }