zoukankan      html  css  js  c++  java
  • poj2685

    简单题

    View Code
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    using namespace std;

    #define maxl 20

    char st1[maxl], st2[maxl];

    int getd(char *st, char a)
    {
    int len = strlen(st);
    int x = -1;
    for (int i = 0; i < len; i++)
    if (st[i] == a)
    {
    x = i;
    break;
    }
    if (x == -1)
    return 0;
    if (x == 0 || st[x - 1] > '9' || st[x - 1] < '0')
    return 1;
    return st[x - 1] - '0';
    }

    int cal(char *st)
    {
    int ans = 0;
    ans += getd(st, 'm') * 1000;
    ans += getd(st, 'c') * 100;
    ans += getd(st, 'x') * 10;
    ans += getd(st, 'i');
    return ans;
    }

    void print(int a)
    {
    int b = a / 1000;
    if (b > 1)
    putchar('0' + b);
    if (b != 0)
    putchar('m');
    b = a / 100 % 10;
    if (b > 1)
    putchar('0' + b);
    if (b != 0)
    putchar('c');
    b = a / 10 % 10;
    if (b > 1)
    putchar('0' + b);
    if (b != 0)
    putchar('x');
    b = a % 10;
    if (b > 1)
    putchar('0' + b);
    if (b != 0)
    putchar('i');
    putchar('\n');
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--)
    {
    scanf("%s%s", st1, st2);
    int a = cal(st1);
    int b = cal(st2);
    print(a + b);
    }
    return 0;
    }

  • 相关阅读:
    ActionMQ
    解决Session共享
    Linux中使用keepalived高可用工具解决宕机问题
    Linux安装Nginx
    Nginx基础
    多线程(1)
    单例模式1(3)
    创建型模式5种(2)
    7原则(1)
    反射使用案例(2)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2199610.html
Copyright © 2011-2022 走看看