C++ 简单模拟谷歌数字1000以内数字翻译
谷歌翻译

程序翻译

代码:
#include
#include
using namespace std;//对应字符
string NUMBER[] = {"","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ","eleven ","twelve ","thirteen ","fourteen " ,"fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};string NUMBERtwo[] = {"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};class MyBot
{
public:void putinfo(int a);//读法private:char name[25];char type[25];
};//打印信息
void MyBot::putinfo(int a)
{int b = a % 100;//翻译1000以内的数if (a/100 != 0){cout << NUMBER[a / 100] << "hundred ";if (b!=0){cout << "and ";}}if (b < 20){cout << NUMBER[b];}else{cout << NUMBERtwo[b / 10];if (b%10 != 0){cout << "\b-" << NUMBER[b % 10];}}}int main() {int number;cout << "请输入要翻译的数字:";cin >> number;MyBot bot;bot.putinfo(number);return 0;
}```
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
