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

G++ AC ,C++ WA,Why?

Posted by huangkun at 2008-07-24 00:57:33 on Problem 3654
#include<iostream>
using namespace std;
char line[200];
int reg[30][30];
int main()
{
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	int c=0;
	while(scanf("%s",line)!=EOF&&line[0]!='#')
	{
		memset(reg,0,sizeof(reg));
		int i,j,k,t;
		for(k=0,i=0;line[k];++k)
		{
			if(line[k]=='-')
				for(;i<k;++i)
					for(j=k+1;line[j]&&line[j]!=',';++j)
						reg[line[i]-'A'][line[j]-'a']=0;
			if(line[k]=='+')
				for(;i<k;++i)
					for(j=k+1;line[j]&&line[j]!=',';++j)
						reg[line[i]-'A'][line[j]-'a']=1;
			if(line[k]=='=')
				for(;i<k;++i)
				{
					memset(reg[line[i]-'A'],0,sizeof(reg[line[i]-'A']));
					for(j=k+1;line[j]&&line[j]!=',';++j)
						reg[line[i]-'A'][line[j]-'a']=1;
				}
			if(line[k]==',')
				i=k+1;	
		}
		printf("%d:",++c);
		for(i=0;i<26;++i)
		{
			k=0;
			for(j=0;j<26;++j)
				k+=reg[i][j];
			if(k!=0)
			{
				printf("%c",'A'+i);
				for(j=i+1;j<26;++j)
				{
					k=0;
					for(t=0;t<26;++t)
						k+=reg[j][t];
					if(k!=0)
					{
						if(memcmp(reg[i],reg[j],sizeof(reg[i]))==0)
						{
							printf("%c",'A'+j);
							memset(reg[j],0,sizeof(reg[j]));
						}
						else
							break;
					}
				}
				for(j=0;j<26;++j)
					if(reg[i][j])printf("%c",'a'+j);
			}
		}
		printf("\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