加强数据?
查看原帖
加强数据?
1365062
Deric456楼主2025/7/31 15:23

如下的代码1011就会出问题:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	string b[9]={"one","two","three","four","five","six","seven","eight","nine"};
	string c[9]={"ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
	string d[9]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
	cin>>a;
	if(a==0){
		cout<<"zero";
	}else if(a%1000==0){
		cout<<b[a/1000-1]<<' '<<"thousand";
	}else if(a>1000&&a%1000>100&&a%100<20&&a%100>10){
		cout<<b[a/1000-1]<<" thousand "<<b[(a%1000)/100-1]<<" hundred "<<d[a%100-11];
	}else if(a>100&&a%100>10&&a%100<20){
		cout<<b[a/100-1]<<" hundred "<<d[a%100-11];
	}else if(a<10){
		cout<<b[a-1];
	}else if(a<1000&&a>100&&(a%100)%10==0){
		cout<<b[a/100-1]<<" hundred "<<c[(a%100)/10-1];
	}else if(a>10&&a<20){
		cout<<d[a-11];
	}else if(a>1000&&a%100==0){
		cout<<b[a/1000-1]<<' '<<"thousand"<<' '<<b[a%1000/100-1]<<' '<<"hundred";
	}else if(a<1000&&a%100==0){
		cout<<b[a/100-1]<<" hundred";
	}else if(a>1000&&a%1000<=10){
		cout<<b[a/1000-1]<<" thousand and "<<b[a%1000-1];
	}else if(a<1000&&a%100<=10){
		cout<<b[a/100-1]<<" hundred and "<<b[a%100-1];
	}else{
		if(a>999&&a%1000!=0){
			cout<<b[a/1000-1]<<" thousand ";
			if(a%1000/100==0) cout<<"and"<<' ';
			else cout<<b[a%1000/100-1]<<" hundred ";
			if(a%100/10==0) cout<<"and"<<' ';
			else cout<<c[a%100/10-1]<<' ';
			if(a%10!=0){
				cout<<b[a%10-1];
			}
		}else if(a>99&&a%100!=0){
			cout<<b[a%1000/100-1]<<' '<<"hundred ";
			if(a%100/10==0) cout<<" and"<<' ';
			else cout<<c[a%100/10-1];
			if(a%10!=0){
				cout<<' '<<b[a%10-1];
			}	
		}else if(a>9&&(a>=20)){
			cout<<c[a%100/10-1];
			if(a%10!=0){
				cout<<' '<<b[a%10-1];
			}		
		}else if(a/10==0){
			if(a%10!=0){
				cout<<b[a%10-1];
			}		
		}	
	}	
}

码风不佳

2025/7/31 15:23
加载中...