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 |
数组下标法太low,用指针遍历字符串才是可取之道。代码供字符串遍历不熟悉的童鞋参考int mp[26][26] = {}; int main() { char s[90],*p,*q,c,f; // 用cur记入哈希表mp中,遍历一遍字符串后cur自增,省得每次ZeroMemory int cur = 1; int bs, d, i; while (1){ bs = 1; scanf("%s", s); if ('*' == s[0])break; // 长度为1或者2的字符串不用考虑 if (0 != s[1] && 0 != s[2]) { d = 1; while (bs) { // p保持在字符串首,q移动d个距离如果到了字符串结尾,跳出整个循环 p = s;q = s; for (i = 0; i < d; i++) { q++; if (0 == *q)break; } if (0 == *q)break; while (c = *q++){ f = *p++; if (mp[f - 'A'][c - 'A'] == cur){ bs = 0; break;} else mp[f - 'A'][c - 'A'] = cur; } cur++; d++; } } if (bs)printf("%s is surprising.\n", s); else printf("%s is NOT surprising.\n", s); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator