搬了leetcode的代码
/* ID: yingzho1 LANG: C++ TASK: preface */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> using namespace std; ifstream fin("preface.in"); ofstream fout("preface.out"); int N; ] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'}; string intToRoman(int num) { ; string ret; ; i >= ; i -= ) { int digit = num / scale; ) { ) ret = ret + string(digit, symbol[i]); ) ret = ret + symbol[i] + symbol[i+]; ) ret = ret + symbol[i+]; ) ret = ret + symbol[i+] + , symbol[i]); ) ret = ret + symbol[i] + symbol[i+]; } num %= scale; scale /= ; } return ret; } int main() { fin >> N; map<char, int> res; ; i <= N; i++) { string s = intToRoman(i); ; j < s.size(); j++) { res[s[j]]++; } } ; i < ; i++) { ) fout << symbol[i] << " " << res[symbol[i]] << endl; } ; }