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 |
97题 奔100中 自认为干净的算法 贴个代码 留个念~反复比较两个字串中相同位置相同字符个数2以上个就说明是not 比如aabb 就比较aab与abb 两个相同(接下来aa与bb a与b就不用比了) so……not 再如 abcda 比较abcd bcda 0个 abc cda 0个 ab da 0个 a a 1个 最多的1个 so……YES #include<stdio.h> #include<string.h> int main() { char str[80]; int count; int i,j,k; int len; scanf("%s",str); while(str[0]!='*'){ len=strlen(str); for(i=0;i<len;i++){ count=0; for(j=i+1,k=0;j<len;j++,k++){ if(str[j]==str[k]) count++; if(count>=2) break; } if(count>=2) break; } if(count>=2) printf("%s is NOT surprising.\n",str); else printf("%s is surprising.\n",str); scanf("%s",str); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator