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多次了,真不知序数怎么搞了,已AC的帮忙看看

Posted by Skyscraper at 2006-07-09 21:28:39 on Problem 2247
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

string GetSuffix(int num)
{
	string str;
	if(num>=4 && num<=19)
	{
		str = "th";
	}
	else
	{
		switch(num%10)
		{
		case 1:str ="st";break;
		case 2:str ="nd";break;
		case 3:str ="rd";break;
		default:
			str ="th";
		}
	}
	return str;
}

vector<int> allNum(6001);

int main()
{
	const int allFour[4] ={ 2, 3, 5, 7};
	int  fourNum[4];
	int  pos[4]={0, 0, 0, 0};
	allNum[0]=1;
	int min;
	for(int i=1; i<6000; i++)
	{		 
		for(int j=0; j<4; j++)
		{
			fourNum[j] = allFour[j]*allNum[pos[j]];
		}
		min=*min_element(&fourNum[0], &fourNum[0]+4);
	    for(int k=0; k<4; k++)
		{
			if(fourNum[k]==min)
			{
				pos[k]++;
			}
		}
		allNum[i] = min;
	}

	int num;	
    while(true)
	{	
		cin>>num;
		if(num==0)break;
		cout<<"The "<<num<<GetSuffix(num)
			<<" humble number is "<<allNum[num-1]<<"."<<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