Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
上面提的情况都考虑了还是过不了!!!!!!!!!!!!帮忙看一下,我是个新手,谢谢了,哥哥们!!!!!!!!#include<stdio.h> #include<string.h> int main() { int i,j,k; k=0; char a[150]; while(gets(a)) { k++; printf("sample output #%d\n",k); int l=strlen(a); int he=0,da=0,g=0; if(a[0]>='A'&&a[0]<='Z')//开头大写或是'_'的 { printf("Error!\n"); continue; } else if(a[0]<'a'||a[0]>'z') { printf("Error!\n"); continue; } if(a[l-1]=='_')//最后是'_'的 { printf("Error!\n"); continue; } for(i=0;i<l;i++) { if(a[i]>='A'&&a[i]<='Z') da++; else if(a[i]=='_') { he++; if(a[i+1]=='_') { printf("Error!\n"); g=1; break; } } else if(a[i]<'a'||a[i]>'z') { printf("Error!\n"); g=1; break; } } if(da>0&&he>0) { printf("Error!\n"); continue; } if(g==1) continue; if(da>0) for(i=0;i<l;i++) { if(a[i]>='A'&&a[i]<='Z') { printf("_"); a[i]=a[i]+32; } printf("%c",a[i]); } else if(he>0) { for(i=0;i<l;i++) { if(a[i]=='_') { a[i+1]=a[i+1]-32; continue; } printf("%c",a[i]); } } else printf("%s",a); printf("\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator