- 转罗马数字
- 2024-06-17 10:00:12 @
//4000~4999怎么处理啊?
#include<bits/stdc++.h>
using namespace std;
int a[8]={0,1,5,10,50,100,500,1000};
char c[8]={0,'i','v','x','l','c','d','m'};
int main()
{
int x;cin>>x;
for(int i=7;i>=1;i--)
{
if(x>=a[i])
{
while(x>0)
{
int at=a[i];
char ct=c[i];
int xc=i;
while(x/at<4&&x>0)
{
for(int j=1;j<=x/at;j++)
cout<<ct;
x%=at;
for(int j=i-1;j>=1;j--)
if(x>=a[j])
{
at=a[j];
ct=c[j];
xc=j;
break;
}
}
if(x/at==4)
{
cout<<c[xc]<<c[xc+1];
x%=at;
for(int j=i-1;j>=1;j--)
if(x>=a[j])
{
at=a[j];
ct=c[j];
xc=j;
break;
}
}
}
break;
}
}
return 0;
}
1 条评论
-
2230134娄耀 (2212238) LV 8 @ 2024-06-27 17:10:42
#include<bits/stdc++.h> using namespace std; int a[13]={1000,900,500,400,100,90,50,40,10,9,5,4,1}; string st[13]={"m","cm","d","cd","c","xc","l","xl","x","ix","v","iv","i"}; int main() { ios::sync_with_stdio(false); int x;cin>>x; for(int i=0;i<13;i++) { while(a[i]<=x) { x-=a[i]; cout<<st[i]; } } return 0; }
- 1
信息
- ID
- 2719
- 难度
- 9
- 分类
- (无)
- 标签
- 递交数
- 6
- 已通过
- 3
- 通过率
- 50%
- 上传者