杭电ACM HDOJ 1924 CIVIC DILL MIX
2013-02-07 21:56
260 查看
#include <cstdio> #include <iostream> using namespace std; char word[20]; int getvalue(char word){ switch(word){ case 'I':return 1; case 'V':return 5; case 'X':return 10; case 'L':return 50; case 'C':return 100; case 'D':return 500; case 'M':return 1000; } } //符号转化为数字 int SymtoNum(char word[]){ int i,sum; i=sum=0; while(word[i+1]){ if(getvalue(word[i])<getvalue(word[i+1])){ sum-=getvalue(word[i]); } else sum+=getvalue(word[i]); i++; } sum+=getvalue(word[i]); return sum; } //数字转化为符号 void NumtoSym(char word[],int num){ int i=0; while(num){ if(num>=1000){ word[i++]='M';num-=1000;} else if(num>=900){ word[i++]='C';num+=100;} else if(num>=500){ word[i++]='D';num-=500;} else if(num>=400){ word[i++]='C';num+=100;} else if(num>=100){ word[i++]='C';num-=100;} else if(num>=90){ word[i++]='X';num+=10;} else if(num>=50){ word[i++]='L';num-=50;} else if(num>=40){ word[i++]='X';num+=10;} else if(num>=10){ word[i++]='X';num-=10;} else if(num>=9){ word[i++]='I';num+=1;} else if(num>=5){ word[i++]='V';num-=5;} else if(num>=4){ word[i++]='I';num+=1;} else if(num>=0){ word[i++]='I';num-=1;} } word[i]='\0'; } int main(){ int n; int i,ans; int count=0; while(cin>>n,n){ ans=0; count++; for(i=0;i<n;i++){ cin>>word; ans+=SymtoNum(word); } NumtoSym(word,count); printf("Case %s: ",word); NumtoSym(word,ans); printf("%s\n",word); } return 0; }
相关文章推荐
- 【HDOJ】1924 CIVIC DILL MIX
- HDOJ 4540 威威猫系列故事——打地鼠 杭电 ACM
- 杭电ACM HDOJ 2206 IP的计算
- HDOJ 2553 N皇后问题 杭电 ACM
- ACM-杭电 HDOJ-1216 模拟,链表
- HDOJ 1097 A hard puzzle 杭电 ACM
- HDOJ 1058 Humble Numbers 杭电 ACM
- HDOJ 2602 Bone Collector 杭电 ACM
- HDOJ 1421 搬寝室 杭电 ACM
- HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 杭电 ACM
- HDOJ 1272 小希的迷宫 杭电 ACM
- HDOJ 1856 More is better 杭电 ACM
- 规律题 CIVIC DILL MIX
- HDOJ 1160 FatMouse's Speed 杭电 ACM
- HDOJ 4508 湫湫系列故事——减肥记I 杭电 ACM
- 杭电ACM-HDOJ1466计算直线的交点数(动态规划)
- 杭电 ACM HDOJ 2045 不容易系列之(3)—— LELE的RPG难题
- CIVIC DILL MIX
- HDOJ 1215 七夕节 杭电 ACM
- HDOJ 1087 Super Jumping! Jumping! Jumping! 杭电 ACM