文章
5
粉丝
9
获赞
2
访问
3.3k
思路可以看这个链接:https://biaodigit.github.io/LeetCode/0012/#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF-%E8%B4%AA%E5%BF%83%E7%AE%97%E6%B3%95
#include<bits/stdc++.h>
using namespace std;
int arr[20]={1000,900,500,400,100,90,50,40,10,9,5,4,1};//13
string sl[20]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
int main(){
int n;
cin>>n;
vector<string>ans;
for(int i=0;i<13;i++){
if(n<arr[i])continue;
while(n>=arr[i]){
n-=arr[i];
ans.push_back(sl[i]);
}
}
for(int i=0;i<ans.size();i++){
cout<<ans[i];
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发