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

zoj 2791 Numeral System

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

zoj 2791 Numeral System

#include<iostream>#include<queue>#include<cstdio>#include<string.h>#include<cstdlib>using namespace std;enum {    SIZ = 104,};const char *unit = "ixcm";char buf[SIZ];int getUnit(char c){    int ret = 1;    for(int i=0; unit[i]&&unit[i]!=c; ++i, ret*=10)        ;    return ret;}int parse(char *s){    int ret = 0, d=1;    for(;*s;++s){        if (isdigit(*s)){ d = *s - '0';        } else { d *= getUnit(*s); ret += d; d = 1;        }    }    return ret;}void output(int val){    int u = 1000, d;    for(int i=3; i>=0; --i, u/=10){        d = val / u;        if (d){ if (d > 1){     printf("%d", d); } printf("%c", unit[i]); val -= d * u;        }    }    printf("n");}void fun(){    int a, b;    char *p;    static const char *sps=" tn";    fgets(buf, SIZ, stdin);    p = strtok(buf, sps);    a = parse(p);    p = strtok(NULL, sps);    b = parse(p);    a += b;    output(a);}int main(){    int tst;    scanf("%d ", &tst);    while(tst-- > 0){        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372356.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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