程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> poj 2247 Humble Numbers

poj 2247 Humble Numbers

編輯:C++入門知識

poj 2247 Humble Numbers



Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9453 Accepted: 4440

題目大意:找出所有因子中只有2,3,5,7的數,給出n,求出第n個這樣 只有6000不到打表

注意第11 12 13 的輸出與 1 2 3 幾十一 幾十二 幾十三 的輸出不同



#include 
#include 
using namespace std;

long humble[6000];

int main()
{
    int i, n2, n3, n5, n7;
    humble[1] = 1;
    n2 = 1;
    n3 = 1;
    n5 = 1;
    n7 = 1;
    for (i = 2; i <= 5900; i++)
    {
        humble[i] = min(min(humble[n2]*2, humble[n3]*3), min(humble[n5]*5, humble[n7]*7));
        if (humble[i] == humble[n2]*2)
            n2++;
        if (humble[i] == humble[n3]*3)
            n3++;
        if (humble[i] == humble[n5]*5)
            n5++;
        if (humble[i] == humble[n7]*7)
            n7++;
    }
    
    int num;
    while (cin >> num && num)
    {
          int tmp1, tmp2;
          tmp1 = num % 10;
          tmp2 = num % 100;
          if (tmp1 == 1)
          {
             if (tmp2 == 11)
                 cout << "The " << num << "th humble number is " << humble[num] << "." << endl;
             else 
                 cout << "The " << num << "st humble number is " << humble[num] << "." << endl;
          }
          else if (tmp1 == 2)
          {
             if (tmp2 == 12)
                 cout << "The " << num << "th humble number is " << humble[num] << "." << endl;
             else
                 cout << "The " << num << "nd humble number is " << humble[num] << "." << endl;
          }
          else if (tmp1 == 3)
          {
             if (tmp2 == 13)
                 cout << "The " << num << "th humble number is " << humble[num] << "." << endl;
             else
                 cout << "The " << num << "rd humble number is " << humble[num] << "." << endl;
          }
          else 
             cout << "The " << num << "th humble number is " << humble[num] << "." << endl;
    }
    
    system("pause");
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved