栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2685 Numeral System

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2685 Numeral System

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#define CNT 2#define MAXSIZE 9int main(){int cnt;scanf("%d",&cnt);while( cnt-- ){char input[CNT][MAXSIZE];int  result[CNT] = {0,0};scanf("%s",input[0]);scanf("%s",input[1]);for(int j=0; j<2; j++){for(int i=0; i<strlen(input[j]); i++){if(isdigit(input[j][i])){int temp = atoi(&input[j][i]);switch(input[j][++i]){case 'm':result[j] += 1000 * temp;break;case 'c':result[j] += 100 * temp;break;case 'x':result[j] += 10 * temp;break;case 'i':result[j] += temp;break;default:break;}}else{switch(input[j][i]){case 'm':result[j] += 1000 ;break;case 'c':result[j] += 100 ;break;case 'x':result[j] += 10 ;break;case 'i':result[j] += 1;break;default:break;}}}}int sum = result[0] + result[1];char print_sum[MAXSIZE] = {0};int index = 0;for(int div=1000; div!=0 ; div/=10){if(sum / div){if(sum / div != 1){print_sum[index++] = sum/div + '0'; }switch(div){case 1000:print_sum[index] = 'm';break;case 100:print_sum[index] = 'c';break;case 10:print_sum[index] = 'x';break;case 1:print_sum[index] = 'i';break;}index ++;sum %= div;}}printf("%sn",print_sum);}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371176.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号