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

WA……HELP

Posted by mickeyandkaka at 2010-11-12 21:02:00 on Problem 2608
#include <stdio.h>
#include <string.h>
int fun(char ch[],int a[]);
int f1(char ch);
int main()
{
	char str[25];
	int i=0,j,n,s,a[25];
	
	memset(a,'\0',sizeof(a));
	
	while(scanf("%s",&str[i])!=EOF)
	{
		n=fun(str,a);
		for(j=0;j<n;j++)
		{
			if(j==0)
			{
				if(a[j]==0) continue;
				else printf("%d",a[j]);
			}
			else
			{
				if(a[j]==0||a[j]==a[j-1]) continue;
				else printf("%d",a[j]);
			}
			
		}
		if(i<n) printf("\n");
		memset(a,'\0',sizeof(a));
		memset(str,'\0',sizeof(str));
	}	
	return 0;	
}

int fun(char ch[],int a[])
{
	int i,n,s=0;
	n=strlen(ch);
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			if(f1(ch[i])==0) continue;
			else a[i]=f1(ch[i]);	
		}
		else
		{
			if(f1(ch[i])==0||f1(ch[i])==f1(ch[i-1])) continue;
			else a[i]=f1(ch[i]);	
		}
	}	
}
int f1(char ch)
{
	if(ch=='B'||ch=='F'||ch=='P'||ch=='V') return 1;
	if(ch=='C'||ch=='G'||ch=='J'||ch=='K'||ch=='Q'||ch=='S'||ch=='X') return 2;
	if(ch=='D'||ch=='T') return 3;
	if(ch=='L') return 4;
	if(ch=='M'||ch=='N') return 5;	
	if(ch=='R') return 6;
	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