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的代码

Posted by cpp0600648238 at 2007-07-23 23:50:58 on Problem 3113
In Reply To:WA得快死了,救命啊! Posted by:cpp0600648238 at 2007-07-23 23:45:58
#include<iostream>
#include<cstring>
#include<memory>
using namespace std;
char l[1001][101]={0};
bool visited[1000]={0},f;
int L;
int op(int a[10],int n,char *ptr)
{
	if(visited[n])
	{
		f=0; return 999999;
	}
	visited[n]=1;
	int r[10],i;
	for(i=0;i<10;i++) r[i]=a[i];
	r[0]=n;
	char *tmp1=ptr,*tmp2=ptr;
	while(tmp1-l[0]<L*101)
	{
		if(!f) return 999999;
		if(strstr(tmp1,"ENDIF"))
		{
			tmp1+=sizeof(char)*101; continue;
		}
		tmp2=tmp1;
		while(*tmp2&&(*tmp2)!=' ') tmp2++;
		tmp2++;
		if(strstr(tmp1,"MOV"))
		{
			tmp2++;
			int num=*tmp2-'0'; tmp2+=2;
			if(*tmp2=='R')
			{
				tmp2++; r[num]=r[*tmp2-'0'];
			}
			else r[num]=atoi(tmp2);
			tmp1+=sizeof(char)*101;
		}
		else if(strstr(tmp1,"ADD"))
		{
			tmp2++;
			int num=*tmp2-'0'; tmp2+=2;
			if(*tmp2=='R')
			{
				tmp2++; r[num]+=r[*tmp2-'0'];
			}
			else r[num]+=atoi(tmp2);
			r[num]%=1000;
			tmp1+=sizeof(char)*101;
		}
		else if(strstr(tmp1,"SUB"))
		{
			tmp2++;
			int num=*tmp2-'0'; tmp2+=2;
			if(*tmp2=='R')
			{
				tmp2++; r[num]-=r[*tmp2-'0'];
			}
			else r[num]-=atoi(tmp2);
			if(r[num]<0) r[num]+=1000;
			tmp1+=sizeof(char)*101;
		}
		else if(strstr(tmp1,"MUL"))
		{
			tmp2++;
			int num=*tmp2-'0'; tmp2+=2;
			if(*tmp2=='R')
			{
				tmp2++; r[num]*=r[*tmp2-'0'];
			}
			else r[num]*=atoi(tmp2);
			r[num]%=1000;
			tmp1+=sizeof(char)*101;
		}
		else if(strstr(tmp1,"DIV"))
		{
			tmp2++;
			int num=*tmp2-'0'; tmp2+=2;
			if(*tmp2=='R')
			{
				tmp2++;
				if(!r[*tmp2-'0']) r[num]=0;
				else r[num]/=r[*tmp2-'0'];
			}
			else if(atoi(tmp2)) r[num]/=atoi(tmp2);
			else r[num]=0;
			tmp1+=sizeof(char)*101;
		}
		else if(strstr(tmp1,"MOD"))
		{
			tmp2++;
			int num=*tmp2-'0'; tmp2+=2;
			if(*tmp2=='R')
			{
				tmp2++;
				if(!r[*tmp2-'0']) r[num]=0;
				else r[num]%=r[*tmp2-'0'];
			}
			else if(atoi(tmp2)) r[num]%=atoi(tmp2);
			else r[num]=0;
			tmp1+=sizeof(char)*101;
		}
		else if(strstr(tmp1,"IFEQ"))
		{
			int num,num1;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			while(*tmp2!=',') tmp2++;
			tmp2++;
			if(*tmp2=='R')
			{
				tmp2++; num1=r[*tmp2-'0'];
			}
			else num1=atoi(tmp2);
			if(num1==num)
			{
				tmp1+=sizeof(char)*101; continue;
			}
			else
			{
				int ifc=1;
				while(tmp1-l[0]<L*101&&ifc)
				{
					tmp1+=sizeof(char)*101;
					if(strstr(tmp1,"ENDIF"))
					{
						ifc--; continue;
					}
					if(strstr(tmp1,"IF")) ifc++;
				}
				if(tmp1-l[0]>=L*101)
				{
					f=0; return 999999;
				}
				tmp1+=sizeof(char)*101;
			}
		}
		else if(strstr(tmp1,"IFNEQ"))
		{
			int num,num1;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			while(*tmp2!=',') tmp2++;
			tmp2++;
			if(*tmp2=='R')
			{
				tmp2++; num1=r[*tmp2-'0'];
			}
			else num1=atoi(tmp2);
			if(num1!=num)
			{
				tmp1+=sizeof(char)*101; continue;
			}
			else
			{
				int ifc=1;
				while(tmp1-l[0]<L*101&&ifc)
				{
					tmp1+=sizeof(char)*101;
					if(strstr(tmp1,"ENDIF"))
					{
						ifc--; continue;
					}
					if(strstr(tmp1,"IF")) ifc++;
				}
				if(tmp1-l[0]>=L*101)
				{
					f=0; return 999999;
				}
				tmp1+=sizeof(char)*101;
			}
		}
		else if(strstr(tmp1,"IFG"))
		{
			int num,num1;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			while(*tmp2!=',') tmp2++;
			tmp2++;
			if(*tmp2=='R')
			{
				tmp2++; num1=r[*tmp2-'0'];
			}
			else num1=atoi(tmp2);
			if(num>num1)
			{
				tmp1+=sizeof(char)*101; continue;
			}
			else
			{
				int ifc=1;
				while(tmp1-l[0]<L*101&&ifc)
				{
					tmp1+=sizeof(char)*101;
					if(strstr(tmp1,"ENDIF"))
					{
						ifc--; continue;
					}
					if(strstr(tmp1,"IF")) ifc++;
				}
				if(tmp1-l[0]>=L*101)
				{
					f=0; return 999999;
				}
				tmp1+=sizeof(char)*101;
			}
		}
		else if(strstr(tmp1,"IFL"))
		{
			int num,num1;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			while(*tmp2!=',') tmp2++;
			tmp2++;
			if(*tmp2=='R')
			{
				tmp2++; num1=r[*tmp2-'0'];
			}
			else num1=atoi(tmp2);
			if(num<num1)
			{
				tmp1+=sizeof(char)*101; continue;
			}
			else
			{
				int ifc=1;
				while(tmp1-l[0]<L*101&&ifc)
				{
					tmp1+=sizeof(char)*101;
					if(strstr(tmp1,"ENDIF"))
					{
						ifc--; continue;
					}
					if(strstr(tmp1,"IF")) ifc++;
				}
				if(tmp1-l[0]>=L*101)
				{
					f=0; return 999999;
				}
				tmp1+=sizeof(char)*101;
			}
		}
		else if(strstr(tmp1,"IFGE"))
		{
			int num,num1;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			while(*tmp2!=',') tmp2++;
			tmp2++;
			if(*tmp2=='R')
			{
				tmp2++; num1=r[*tmp2-'0'];
			}
			else num1=atoi(tmp2);
			if(num>=num1)
			{
				tmp1+=sizeof(char)*101; continue;
			}
			else
			{
				int ifc=1;
				while(tmp1-l[0]<L*101&&ifc)
				{
					tmp1+=sizeof(char)*101;
					if(strstr(tmp1,"ENDIF"))
					{
						ifc--; continue;
					}
					if(strstr(tmp1,"IF")) ifc++;
				}
				if(tmp1-l[0]>=L*101)
				{
					f=0; return 999999;
				}
				tmp1+=sizeof(char)*101;
			}
		}
		else if(strstr(tmp1,"IFLE"))
		{
			int num,num1;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			while(*tmp2!=',') tmp2++;
			tmp2++;
			if(*tmp2=='R')
			{
				tmp2++; num1=r[*tmp2-'0'];
			}
			else num1=atoi(tmp2);
			if(num<=num1)
			{
				tmp1+=sizeof(char)*101; continue;
			}
			else
			{
				int ifc=1;
				while(tmp1-l[0]<L*101&&ifc)
				{
					tmp1+=sizeof(char)*101;
					if(strstr(tmp1,"ENDIF"))
					{
						ifc--; continue;
					}
					if(strstr(tmp1,"IF")) ifc++;
				}
				if(tmp1-l[0]>=L*101)
				{
					f=0; return 999999;
				}
				tmp1+=sizeof(char)*101;
			}
		}
		else if(strstr(tmp1,"CALL"))
		{
			int num;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			r[9]=op(r,num,ptr);
			tmp1+=sizeof(char)*101;
		}
		else if(strstr(tmp1,"RET"))
		{
			int num;
			if(*tmp2=='R')
			{
				tmp2++; num=r[*tmp2-'0'];
			}
			else num=atoi(tmp2);
			visited[n]=0;
			return num;
		}
	}
	if(tmp1-l[0]>=L*101)
	{
		f=0; return 999999;
	}
	return 0;
}
main()
{
	int N,i;
	int r[10],num;
	char *p=0;
	while(cin>>L>>N&&L+N)
	{
		cin.get();
		memset(visited,0,sizeof(visited));
		memset(l,0,sizeof(l));
		f=1;
		for(i=0;i<L;i++) cin.getline(l[i],100);
		memset(r,0,sizeof(r));
		p=l[0];
		num=op(r,N,p);
		if(f) cout<<num<<endl;
		else cout<<"*"<<endl;
	}
}

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