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 lbcharry at 2006-03-11 22:36:34 on Problem 2121
#include <iostream.h>
#include <string.h>

#define  cmp(s)  strcmp(s, str)

int getnum(char *str)
{
	if(cmp("zero") == 0) return 0;
	else if(cmp("one") == 0) return 1;
	else if(cmp("two") == 0) return 2;
	else if(cmp("three") == 0) return 3;
	else if(cmp("four") == 0) return 4;
	else if(cmp("five") == 0) return 5;
	else if(cmp("six") == 0) return 6;
	else if(cmp("seven") == 0) return 7;
	else if(cmp("eight") == 0) return 8;
	else if(cmp("nine") == 0) return 9;
	else if(cmp("ten") == 0) return 10;
	else if(cmp("eleven") == 0) return 11;
	else if(cmp("twelve") == 0) return 12;
	else if(cmp("thirteen") == 0) return 13;
	else if(cmp("fourteen") == 0) return 14;
	else if(cmp("fifteen") == 0) return 15;
	else if(cmp("sixteen") == 0) return 16;
	else if(cmp("seventeen") == 0) return 17;
	else if(cmp("eighteen") == 0) return 18;
	else if(cmp("nineteen") == 0) return 19;
	else if(cmp("twenty") == 0) return 20;
	else if(cmp("thirty") == 0) return 30;
	else if(cmp("forty") == 0) return 40;
	else if(cmp("fifty") == 0) return 50;
	else if(cmp("sixty") == 0) return 60;
	else if(cmp("seventy") == 0) return 70;
	else if(cmp("eighty") == 0) return 80;
	else if(cmp("ninety") == 0) return 90;
	else if(cmp("hundred") == 0) return 100;
	else if(cmp("thousand") == 0) return 1000;
	else if(cmp("million") == 0) return 1000000;
	else if(cmp("negative") == 0) return -1;
	return -2;
}

int main()
{
	bool  over = false;
	int   sum, n , t, state , len, i, j, sign , cur;
	int   num[30];
	char  input[200], substring[20];

	while(1)
	{
		cin.getline(input, 100,'\n');
		len = (int)strlen(input);
		if( len == 0) break;
		i = 0; t = 0;
		while(i < len)
		{
			while(input[i] == ' ' && input[i] != '\0') i++;
			j = 0;
			while(input[i] != ' ' && input[i] != '\0') substring[j++] = input[i++];
			substring[j] = '\0';
			num[t++] = getnum(substring);
		}
		num[t++] = -2;
		len = t; t = 0; sign = 1;
		if(num[0] == -1){ sign = -1; t++ ;}
		sum = 0; 
		state = 1;
		n = 0;
		over = false;
		cur = num[t++];
		while(!over)
		{
			switch(state)
			{
			case 1:
				n = cur; cur = num[t++];
				if(cur == -2){ sum += n; over = true; }
				else if(cur >= 0 && cur <= 90) state = 2;
				else if(cur == 100) state = 3;
				else if(cur == 1000) state = 4;
				else if(cur == 1000000) state = 8;
				break;
			case 2:
				n += cur; cur = num[t++];
				if(cur == -2){ sum += n; over = true; }
				else if(cur == 100) state = 3;
				else if(cur == 1000) state = 4;
				else if(cur == 1000000) state = 8;
				break;
			case 3:
				n *= 100; cur = num[t++];
				if(cur == -2){ sum += n; over = true; }
				else if(cur >= 0 && cur <= 90) state = 5;
				else if(cur == 1000) state = 4;
				else if(cur == 1000000) state = 8;
				break;
			case 4:
				sum += n*1000; cur = num[t++];
				if(cur == -2) over = true;
				else if(cur >= 0 && cur <= 90) state = 1;
				break;
			case 5:
				n += cur; cur = num[t++];
				if(cur == -2){ sum += n; over = true; }
				else if(cur >= 0 && cur <= 90) state = 7;
				else if(cur == 1000) state = 4;
				else if(cur == 1000000) state = 8;
				break;
			case 7:
				n += cur; cur = num[t++];
				if(cur == -2){ sum += n; over = true; }
				else if(cur >= 0 && cur <= 90) state = 1;
				else if(cur == 1000) state = 4;
				else if(cur == 1000000) state = 8;
				break;
			case 8:
				sum += n*1000000; cur = num[t++];
				if(cur == -2) over = true;
				else if(cur >= 0 && cur <= 90) state = 1;
				break;

			}
		}
		cout<<sum*sign<<endl;

	}
	
	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