是不是感觉少了什么
以后开头就这个了
这道题叫“爱与愁的一千个伤心的理由”
这题目,绝了
开始吧
题目懒得说
上代码
#includeusing namespace std; const string num[11] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; const string ty[11] = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; const string teen[21] = {"", "", "", "", "", "", "", "", "", "", "", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; int a[5], n, cnt; int main(){ cin>>n; int tmp = n; while(tmp) { a[++cnt] = tmp % 10; tmp /= 10; } int teens = a[2] * 10 + a[1]; if(cnt == 4) { cout << num[a[4]] << ' ';printf("thousand"); if(a[1] == 0 && a[2] == 0 && a[3] == 0) return 0; else if(a[3] == 0 && a[2] && a[1]) { putchar(' '); if(teens >= 11 && teens <= 19) { cout << teen[teens]; return 0; } if(a[2] == 1) cout << " and " << ty[1]; else cout << "and " << ty[a[2]]; putchar(' '); cout << num[a[1]]; } else if(a[3] && !a[2] && a[1]){ putchar(' '); cout << num[a[3]]; printf(" hundred and "); cout << num[a[1]]; } else if(a[3] && a[2] && !a[1]) { putchar(' '); cout << num[a[3]]; printf(" hundred "); if(a[2] == 1) cout << " and " << ty[1]; else cout << ty[a[2]]; } else if(a[3] && !a[2] && !a[1]) { cout << ' ' << num[a[3]]; printf(" hundred"); } else if(!a[3] && a[2] && !a[1]) { if(a[2] == 1) cout << " and " << ty[1]; else cout << ty[a[2]]; } else if(!a[3] && !a[2] && a[1]) cout << " and " << num[a[1]]; else { cout << ' ' << num[a[3]] << " hundred "; if(teens >= 11 && teens <= 19) cout << teen[teens]; else { cout << ty[a[2]] << ' ' << num[a[1]]; } } } else if(cnt == 3) { cout << num[a[3]]; printf(" hundred"); if(!a[2] && !a[1]) return 0; else if(a[2] && !a[1]) { if(a[2] == 1) cout << " and " << ty[1]; else cout << ty[a[2]]; } else if(!a[2] && a[1]) { printf(" and "); cout << num[a[1]]; } else if(teens < 11 || teens > 19) { if(a[2] == 1) cout << " and " << ty[1]; else cout << ty[a[2]]; cout << ' ' << num[a[1]]; } else cout << ' ' << teen[teens]; } else if(cnt == 2) { if(teens >= 11 && teens <= 19) cout << teen[teens]; else if(!a[1]) { if(a[2] == 1) cout << " and " << ty[1]; else cout << ty[a[2]]; } else cout << ty[a[2]] << ' ' << num[a[1]]; } else cout << num[a[1]]; return 0; }
我是大白,每日一更,记得关注!!!



