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

我验证了很多数据都是对的 不知哪还有错 晕死了 大牛能给点数据检验一下吗

Posted by mabodx at 2010-02-09 13:47:53 on Problem 2121 and last updated at 2010-02-09 13:49:08
#include<iostream>
#define m 200
using namespace std;

char a[10][10]={"zero","one", "two","three","four","five","six","seven","eight","nine"},
	b[10][10]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"},
	c[10][10]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"},
	d[10][10]={"negative","hundred","thousand","million"};

char s[m],s1[m];
int n[m],q,k,w,y,t,sum=0;



int main()
{
#ifndef a
	freopen("1\\in.txt","r",stdin);
	freopen("1\\out.txt","w",stdout);
#endif
	
	while(cin.getline(s,m))
	{
		y=1;
		sum=0;
		memset(n,0,sizeof(n));
		if(0 == strcmp(s,""))  break;
		for(q=0;'\0' != s[q];q++)
		{
			if(s[q]==32) continue;
			s1[k++]=s[q];
			
			if(32 ==s[q+1] || '\0'==s[q+1])
			{
				
				s1[k]='\0';
				
				for(w=0;;w++)
				{
					if(!strcmp(s1,d[w]))
					{
						n[0]=-1;
						break;
					}
					if(!strcmp(s1,a[w]))
					{
						n[y++]+=w;
						break;
					}
					if(!strcmp(s1,b[w]))
					{
						n[y++]+=(10+w);
						break;
						
					}
					if(!strcmp(s1,c[w]))
					{
						n[y++]+=(w+2)*10;
						n[y]+=n[y-1];
						n[y-1]=0;
						break;
					}
					if(!strcmp(s1,d[1]))
					{
						n[y]+=n[y-1]*100;
						n[y-1]=0;
						n[++y]+=n[y-1];
						n[y-1]=0;
						break;
					}
					if(!strcmp(s1,d[2]))
					{
						if(n[y])	
						{
							if(n[y]<1000)
							n[y]*=1000;
						}
						else
						{
							n[y]+=n[y-1]*1000;
							n[y-1]=0;
							y++;
						}
						break;
					}
					if(!strcmp(s1,d[3]))
					{
						n[y]+=n[y-1]*1000000;
						n[y-1]=0;
						y++;
						break;
					}

				}
				k=0;
			}
		}
		for(t=1; t<y+1;t++)
		sum+=n[t];
		if(n[0]==-1)
			sum*=(-1);
		cout<<sum<<endl;
	}
#ifndef a
	fclose(stdin);
	fclose(stdout);
#endif
}

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