原題傳送門ios
這道題的題目我是真的無力吐槽,可是,這道題真心不錯QAQ。測試
這道題不難,但很考驗耐心與細心,有各類各樣的小錯誤,若是不細心都不會發現,我最開始的代碼只得了60分,就是忽略了好幾個狀況,而後反覆測試數據,才AC的QAQ(也許只是由於我太弱了)spa
值得一刷code
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<algorithm> #include<cstdlib> #include<cmath> #include<stack> #include<map> using namespace std; int n; int s[5]; string a[25]={"","one","two","three", "four","five","six","seven","eight","nine", "ten","eleven","twelve","thirteen","fourteen", "fifteen","sixteen","seventeen","eighteen","nineteen"}; string x[20]={"","","twenty","thirty","forty","fifty", "sixty","seventy","eighty","ninety"}; int main() { cin>>n; int i=4; while(n!=0) { s[i]=n%10; n/=10; i--; } if(s[1]!=0) cout<<a[s[1]]<<" thousand "; if(s[2]!=0) cout<<a[s[2]]<<" hundred "; else if(s[3]!=0&&s[4]!=0&&(s[2]!=0||s[1]!=0)) cout<<"and "; if(s[3]==0&&s[4]!=0&&(s[2]!=0||s[1]!=0)) cout<<"and "<<a[s[4]]<<endl; else if(s[3]==0&&s[4]!=0) cout<<a[s[4]]<<endl; else if(s[3]==1) cout<<a[s[4]+10]<<endl; else if(s[4]!=0) cout<<x[s[3]]<<" "<<a[s[4]]; if(s[1]==0&&s[2]==0&&s[3]==0&&s[4]==0) cout<<"zero"; return 0; }