USACO :Preface Numbering 解题报告
来源:互联网 发布:淘宝手机充值软件 编辑:程序博客网 时间:2024/06/04 18:22
1.统计N以内(1,2...9) (10,20...90) (100,200,...900) (1000,2000,3000)出现的次数
2.然后再统计I V X L C D M的次数
/*
ID: xpli1
PROG: preface
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define OUT cout
#define IN cin
ofstream fout ("preface.out");
ifstream fin ("preface.in");
typedef struct{
int n;
char c;
}roman;
roman res[7];
int num[5][10];
int N;
void solve(){
int i,j,t,k=1;
int temp = N;
while(temp){
t = temp % 10;
for(i=1; i<k; i++){
for(j=1; j<10; j++){
num[i][j] += t*pow(10,k-2);
}
}
for(i=1; i<t; i++)
num[k][i] += pow(10,k-1);
num[k][t] += N % (int)(pow(10,k-1)) + 1;
temp /= 10;
k++;
}
res[0].c = 'I';
res[0].n = (num[1][1]+num[1][6]+num[1][4]+num[1][9])+2*(num[1][2]+num[1][7])+3*(num[1][3]+num[1][8]);
res[1].c = 'V';
res[1].n = num[1][4]+num[1][5]+num[1][6]+num[1][7]+num[1][8];
res[2].c = 'X';
res[2].n = (num[2][1]+num[2][6]+num[2][4]+num[2][9])+2*(num[2][2]+num[2][7])+3*(num[2][3]+num[2][8])+num[1][9];
res[3].c = 'L';
res[3].n = num[2][4]+num[2][5]+num[2][6]+num[2][7]+num[2][8];
res[4].c = 'C';
res[4].n = (num[3][1]+num[3][6]+num[3][4]+num[3][9])+2*(num[3][2]+num[3][7])+3*(num[3][3]+num[3][8])+num[2][9];
res[5].c = 'D';
res[5].n = num[3][4]+num[3][5]+num[3][6]+num[3][7]+num[3][8];
res[6].c = 'M';
res[6].n = num[4][1]+2*num[4][2]+3*num[4][3]+num[3][9];
}
int main()
{
IN >> N;
solve();
for(int i=0; i<7; i++){
if(res[i].n != 0)
OUT << res[i].c << ' ' << res[i].n << endl;
}
return 0;
}
- USACO :Preface Numbering 解题报告
- USACO 2.2 Preface Numbering (preface)
- 【搜索】【USACO】Preface Numbering
- USACO Preface Numbering
- USACO:Preface Numbering
- USACO-Preface Numbering
- USACO 2.2 Preface Numbering
- USACO 2.2 Preface Numbering
- usaco Section 2.2 Preface Numbering
- [USACO 2.2.1] Preface Numbering
- USACO 2.2.1 Preface Numbering
- USACO 2.2.1 Preface Numbering
- USACO Section 2.2 Preface Numbering
- USACO Section 2.2 Preface Numbering
- USACO 2.2.1 Preface Numbering
- USACO 2.2 Preface Numbering (模拟)
- USACO Section 2.2 Preface Numbering
- usaco Preface Numbering 序言页码
- css中 display属性和visibility的区别
- (7): 建立一个空的 Wave 文件(三种方法)
- (8): 使用 TMediaPlayer 录制 wav 文件
- Dreamweave和VisualStadio的两点比较
- spinlock 与linux内核调度的关系
- USACO :Preface Numbering 解题报告
- ADO中出现IDispatch error #3092的一种情况
- 我眼中的爱情
- jbpm4.3与ssh框架进行整合
- 那些相见恨晚的 JavaScript 技巧
- 读书:《Automatic Wealth》之开源、节流、投资
- usb 鼠标驱动注解及测试
- 写出高性能SQL语句的35条方法分析
- 2010.4.24 一个优秀程序员的必备45个习惯