罗马数字
题解:打表,,,还犹豫了一会儿
#include<bits/stdc++.h> #define ll long long #define P pair<int,int> #define pb push_back #define lson root << 1 #define INF (int)2e9 + 7 #define maxn (int)1e5 + 7 #define rson root << 1 | 1 #define LINF (unsigned long long int)1e18 #define mem(arry, in) memset(arry, in, sizeof(arry)) using namespace std; int T, n; int a[maxn]; string S[maxn]; void Inite(){ S[20] = "XX", S[30] = "XXX", S[40] = "XL", S[50] = "L", S[60] = "LX", S[70] = "LXX", S[80] = "LXXX", S[90] = "XC"; S[200] = "CC", S[300] = "CCC", S[400] = "CD", S[500] = "D", S[600] = "DC", S[700] = "DCC", S[800] = "DCCC", S[900] = "CM"; S[2000] = "MM", S[3000] = "MMM", S[4000] = "MW", S[5000] = "W", S[6000] = "WM", S[7000] = "WMM", S[8000] = "WMMM", S[9000] = "MA"; S[1] = "I", S[2] = "II", S[3] = "III", S[4] = "IV", S[5] = "V", S[6] = "VI", S[7] = "VII", S[8] = "VIII", S[9] = "IX"; S[10] = "X"; S[100] = "C"; S[1000] = "M"; S[10000] = "A"; } void print(int x){ int t = 0; int b[10]; while(x){ b[t++] = x % 10; x /= 10; } for(int i = t - 1; i >= 0; i--) { if(i == 5){ for(int j = 1; j <= b[i] * 10; j++) cout << "A"; } else if(i == 4){ for(int j = 1; j <= b[i]; j++) cout << "A"; } else if(i == 3){ cout << S[1000 * b[i]]; } else if(i == 2){ cout << S[100 * b[i]]; } else if(i == 1){ cout << S[10 * b[i]]; } else cout << S[b[i]]; } cout << endl; } int main() { Inite(); cin >> n; for(int i = 1; i <= n; i++){ int x; cin >> x; print(x); } return 0; }