【USACO2-2-1】序言页码 模拟

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Dadatu_Zhao/article/details/79965311

读懂题目再模拟即可!

 

//usaco2-2-1 序言页码
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int n;
map<char,int> mp;

void work(int k)
{
	int cur=k,cnt=0;
	while(cur>0)
	{
		cnt++;char c1,c2,c3;
		if (cnt==1) c1='i',c2='v',c3='x';
		if (cnt==2) c1='x',c2='l',c3='c';
		if (cnt==3) c1='c',c2='d',c3='m';
		if (cnt==4) c1='m';
		int p=cur%10;
		if (p<=3) mp[c1]+=p;
		else if (p==4) mp[c1]++,mp[c2]++;
			else if (p>=5&&p<=8) mp[c1]+=p-5,mp[c2]++;
				else mp[c1]++,mp[c3]++;
		cur/=10;
	}

}

int main()
{
	scanf("%d",&n);mp.clear();
	for (int i=1;i<=n;i++) work(i);
	if (mp['i']) printf("I %d\n",mp['i']);
	if (mp['v']) printf("V %d\n",mp['v']);
	if (mp['x']) printf("X %d\n",mp['x']);
	if (mp['l']) printf("L %d\n",mp['l']);
	if (mp['c']) printf("C %d\n",mp['c']);
	if (mp['d']) printf("D %d\n",mp['d']);
	if (mp['m']) printf("M %d\n",mp['m']);
	return 0;
}

 

阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页