Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

97题 奔100中 自认为干净的算法 贴个代码 留个念~

Posted by kimhmguen at 2009-12-21 23:08:39 on Problem 3096
反复比较两个字串中相同位置相同字符个数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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator