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

人都写2了...WA求解

Posted by fgwe12 at 2012-01-13 15:09:32 on Problem 2159
#include <stdio.h>
#include <string.h>
int main ()
{
	char str1[1002], str2[1002];	
	while (gets(str1) != '\0')
	{
		int len1, len2;
		int a[1000]={0}, b[1000]={0};
		int i;
		int time1[300]={0}, time2[300]={0};
		int x, y;
		int n, m;
		gets(str2);
		
		//比较长度,不相等重新循环
		len1 = strlen(str1);
		len2 = strlen(str2);
		if (len1 != len2)
		{
			printf("NO\n");
			continue;
		}
		
		//转化为数字数组
		for (i=0; i<len1; i++)
		{
			n = str1[i] - 'A';
			time1[n] ++;
			m = str2[i] - 'A';
			time2[m] ++;
		}
		//当取到不为0的值时,即为第一个值,第二个值
		for (i=0, x=0, y=0; i<len1; i++)
		{
			if (time1[i] != 0)
			{
				a[x] = time1[i];
				x ++;
			}
			if (time2[i] != 0)
			{
				b[y] = time2[i];
				y ++;
			}
		}
		//比较出现个数,不相等重新循环
		if (y != x)
		{
			printf("NO\n");
			continue;
		}
		//比较出现频率
		for (i=0; i<x; i++)
		{
			if (a[i] != b[i])
			{
				printf("NO\n"); //频率不相等,跳出
				break;
			}
		}
		if (i == x)
			printf("YES\n");//频率相等,重新循环
	}
	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