90 wa#5 求调
查看原帖
90 wa#5 求调
1008234
byk_ALEX楼主2025/7/21 18:19

代码:

#include<bits/stdc++.h>
using namespace std;
string a[19] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
string b[2] = {"thousand", "hundred"};
string c[] = {"ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; 
int main(){
	string n;
	cin >> n;
	bool flag = 0;
	if(n.length() == 4){
		for(int i = 0; i < 4; i++){
			if(n[i] == '0')
				continue;
			if(i >= 2 && flag == 0 && n[3] != '0' && int(n[2] - 48) * 10 + int(n[3] - 48) <= 10){
				cout << "and ";
                flag = 1;
			}
			if(i <= 1){
				cout << a[n[i] - 48 - 1] << " ";
				cout << b[i] << " ";
			}
			else if(i == 2 && n[i] == '1'){
				cout << a[int(n[i] - 48) * 10 + int(n[i + 1] - 48) - 1] << " ";
				break;
			}
			else if(i == 2){
				cout << c[n[i] - 48 - 1] << " ";
			}
			else if(i == 3){
				cout << a[n[i] - 1 - 48] << " ";
			}
		} 
	}
	else if(n.length() == 3){
		for(int i = 0; i < 3; i++){
			if(n[i] == '0')
				continue;
			if(i >= 1 && flag == 0 && n[2] != '0' && int(n[1] - 48) * 10 + int(n[2] - 48) <= 10){
				cout << "and ";
				flag = 1;
			}
			if(i == 0){
				cout << a[n[i] - 48 - 1] << " ";
				cout << b[1] << " ";
			}
			else if(i == 1 && n[i] == '1'){
				cout << a[int(n[i] - 48) * 10 + int(n[i + 1] - 48) - 1] << " ";
				break;
			}
			else if(i == 1){
				cout << c[n[i] - 48 - 1] << " ";
			}
			else if(i == 2){
				cout << a[n[i] - 1 - 48] << " ";
			}
		} 
	}
	else if(n.length() == 2){
		if(n[0] == '1'){
			cout << a[int(n[0] - 48) * 10 + int(n[1] - 48) - 1];
		}
		else{
			cout << c[n[0] - 48 - 1] << " ";
			cout << a[n[1] - 1 - 48] << " ";
		}
	}
	else{
		if(n[0] == '0')
			cout << "zero";
		else
		cout << a[n[0] - 1 - 48] << " ";
	}
	return 0; 
}
2025/7/21 18:19
加载中...