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 lcftc at 2005-09-09 12:57:39 on Problem 2247
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

const int MAXN=2000000010;

bool GetCount(int& start,int fact,int times){
    int i;
    for(i=0;i<times;i++){
        if(double(start)>double(MAXN)/double(fact)){
            return false;
        }else{
             start*=fact;   
        }
    }    
    return true;
}    


int main(){
    int a2,a3,a5,a7,i;
    
    vector<int> vet;
    vet.push_back(0);
    for(a2=0;a2<=31;a2++){
        for(a3=0;a3<=20;a3++){
            for(a5=0;a5<=13;a5++){
                for(a7=0;a7<=12;a7++){
                    int cnt=1;
                    if(GetCount(cnt,2,a2) && GetCount(cnt,3,a3) && GetCount(cnt,5,a5) && GetCount(cnt,7,a7)){
                        vet.push_back(cnt);
                    }    
                }
            }
        }
    } 
    sort(vet.begin(),vet.end()); 
    
    int n;
    while(1){
         scanf("%d",&n);
         if(n==0) break;
         int result=vet[n];
         char buff[4];
         if(n<19){
             if(n==1){
                 strcpy(buff,"st");
             }else if(n==2){
                 strcpy(buff,"nd");
             }else if(n==3){
                 strcpy(buff,"rd");
             }else{
                 strcpy(buff,"th");
             }
         }else if(n%10 ==0 && n<=90){
             strcpy(buff,"th");
         }else{
             if(n%10 == 1){
                 strcpy(buff,"st");
             }else if(n%10==2){
                 strcpy(buff,"nd");
             }else if(n%10 == 3){
                 strcpy(buff,"rd");
             }else{
                 strcpy(buff,"th");
             } 
         }                                  
         printf("The %d%s humble number is %d.\n",n,buff,result);   
    }    
    
    
   // system("pause");
    
    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