• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Yiner的ACM

            成長的痕跡
            <2011年3月>
            272812345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統(tǒng)計(jì)

            • 隨筆 - 29
            • 文章 - 0
            • 評論 - 2
            • 引用 - 0

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            字符串處理 A-Metsys Laremun

             

            Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.

            The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.

            For example, character strings

            "5m2c3x4i", "m2c4i" and "5m2c3x"

            correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.

             

            Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.

            For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.

            An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to 1000 + 2*100 + 4*1. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.

            Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.

            Input

            The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).

            n
            specification1
            specification2
            ...
            specificationn

            Each specification is described in a line:

            MCXI-string1 MCXI-string2

            The two MCXI-strings are separated by a space.

             

            You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.

            Output

            For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.

            Sample Input

            10
            xi x9i
            i 9i
            c2x2i 4c8x8i
            m2ci 4m7c9x8i
            9c9x9i i
            i 9m9c9x8i
            m i
            i m
            m9i i
            9m8c7xi c2x8i
            

            Sample Output

            3x
            x
            6cx
            5m9c9x9i
            m
            9m9c9x9i
            mi
            mi
            mx
            9m9c9x9i
            

            posted on 2011-03-20 19:37 Yiner 閱讀(203) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            国产精久久一区二区三区| 久久国产亚洲精品| 99久久人妻无码精品系列| 久久久精品国产sm调教网站| 久久精品国产亚洲精品2020| 欧美一区二区精品久久| 无码任你躁久久久久久| 久久免费的精品国产V∧| 国产毛片久久久久久国产毛片 | 99久久免费只有精品国产| 久久99精品久久久久久9蜜桃| 国内精品伊人久久久影院| 91视频国产91久久久| 无码乱码观看精品久久| 国产精品久久久久AV福利动漫| 久久婷婷五月综合成人D啪| 久久久久久久久久久久中文字幕| 久久精品国产精品亚洲| 久久久久久亚洲精品成人| 亚洲色欲久久久久综合网| 亚洲国产精品久久久久婷婷软件| 亚洲国产精品18久久久久久| 国内精品久久久久久久亚洲| 97精品伊人久久大香线蕉app| 久久夜色精品国产噜噜亚洲a| 99久久精品免费国产大片| av无码久久久久不卡免费网站| 久久久久久精品免费免费自慰| 久久精品成人| 久久夜色撩人精品国产| 久久中文字幕一区二区| 97久久超碰成人精品网站| 日产精品久久久一区二区| 综合网日日天干夜夜久久| 精品一二三区久久aaa片| 麻豆精品久久久久久久99蜜桃| 久久久久99精品成人片三人毛片| 大香网伊人久久综合网2020| 亚洲国产成人久久综合碰碰动漫3d| 精品久久久久久无码专区不卡 | 久久综合日本熟妇|