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

Re:HAHA HEHE 输出YES 怎么A的

Posted by asterix314 at 2009-01-13 20:56:36 on Problem 2159
In Reply To:Re:HAHA HEHE 输出YES 怎么A的 Posted by:MasterLuo at 2009-01-13 20:12:12
我还没说清楚么?
贴代码吧。

----------------------------
#include <stdio.h>
#include <string.h>

#define BUFSIZE 128
#define CNTSIZE 32

void get_metrics(char buf[], int *m0, int *m1, int *m2)
{
	char c;
	int cnt[CNTSIZE];
	int i, t0, t1, t2;

	memset(cnt, 0, sizeof(cnt));
	i = t0 = t1 = t2 = 0;
	while ((c = buf[i++]) != '\0') /* buf contains message */
		++cnt[c - 'A']; /* letter counter */
	for (i=0; i<CNTSIZE; i++)
		if (cnt[i] > 0)
		{
			++t0;
			t1 += cnt[i];
			t2 += cnt[i] * cnt[i];
		}
	*m0 = t0;
	*m1 = t1;
	*m2 = t2;
}

int main()
{
	char buf[BUFSIZE], c;
	int i;
	int t0, t1, t2; /* plain text metrics */
	int s0, s1, s2; /* cypher text metrics */

	scanf("%s", buf);
	get_metrics(buf, &s0, &s1, &s2);
	scanf("%s", buf);
	get_metrics(buf, &t0, &t1, &t2);
	if (s0 == t0 && s1 == t1 && s2 == t2)
		puts("YES");
	else
		puts("NO");
	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