hdoj 1058 Humble Numbers

WA两次,一次没判重,一次不会序数词的定义。。。

#include <iostream> using namespace std; int a[4]; int b[4] = {2, 3, 5, 7}; int ans[5842]; int main() { //freopen("1.txt", "r", stdin); for(int i = 0; i < 4; i++) a[i] = 0; ans[0] = 1; for(int i = 1; i < 5842; i++) { int tmp = 0; for(int j = 1; j < 4; j++) { if(ans[a[j]] * b[j] < ans[a[tmp]] * b[tmp]) tmp = j; } ans[i] = ans[a[tmp]] * b[tmp]; for(int j = 0; j < 4; j++) { if(ans[i] == ans[a[j]] * b[j]) a[j]++; } } int n; while(cin >> n && n != 0) { cout << "The " << n; if(n % 10 == 1 && n % 100 != 11) cout << "st"; else if(n % 10 == 2 && n % 100 != 12) cout << "nd"; else if(n % 10 == 3 && n % 100 != 13) cout << "rd"; else cout << "th"; cout << " humble number is "; cout << ans[n - 1] << "./n"; } return 0; } 

你可能感兴趣的:(hdoj 1058 Humble Numbers)