Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:WA多次了,真不知序数怎么搞了,已AC的帮忙看看In Reply To:WA多次了,真不知序数怎么搞了,已AC的帮忙看看 Posted by:Skyscraper at 2006-07-09 21:28:39 > > #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator