• <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>

            A Za, A Za, Fighting...

            堅信:勤能補拙

            PKU 1016 Numbers That Count

            問題:
            http://poj.org/problem?id=1016

            思路:
            純模擬,需要細心...

            代碼:
             1 #include<stdio.h>
             2 #include<stdlib.h>
             3 #include<string.h>
             4 #define NUM 10 /* 0..9 */
             5 #define UP 15 
             6 #define INPUT_LEN 81
             7 #define MAX_LEN 31
             8 char input[INPUT_LEN], inv[UP][MAX_LEN];
             9 int count[NUM]; 
            10 
            11 void
            12 generate(char *src, char *dst)
            13 {
            14     int i, index, len = strlen(src);
            15     memset(count, 0sizeof(count));
            16     for(i=0; i<len; i++)
            17         ++count[src[i]-'0'];
            18 
            19     index = 0;
            20     for(i=0; i<NUM; i++) {
            21         if(count[i] > 0) {
            22             if(count[i] >= 10) {
            23                 dst[index++= (count[i]/10)+'0';
            24                 dst[index++= (count[i]%10)+'0';
            25             } else {
            26                 dst[index++= count[i]+'0';
            27             }
            28             dst[index++= i+'0';
            29         }
            30     }
            31 }
            32 
            33 void
            34 solve()
            35 {
            36     int i, index = 0;
            37     generate(input, inv[index]);
            38     if(strcmp(input, inv[index]) == 0) {
            39         printf("%s is self-inventorying\n", input);
            40         return;
            41     }
            42     ++index;
            43     while(index < UP) {
            44         generate(inv[index-1], inv[index]);
            45         if(strcmp(inv[index], inv[index-1]) == 0) {
            46             printf("%s is self-inventorying after %d steps\n", input, index);
            47             return;
            48         }
            49         for(i=index-2; i>=0; i--)
            50             if(strcmp(inv[index], inv[i]) == 0) {
            51                 printf("%s enters an inventory loop of length %d\n", input, index-i);
            52                 return;
            53             }
            54         if(index >= 1)
            55             if(strcmp(inv[index], input) == 0) {
            56                 printf("%s enters an inventory loop of length %d\n", input, index+1);
            57                 return;
            58             }
            59         ++index;
            60     }
            61     printf("%s can not be classified after 15 iterations\n", input);
            62 }
            63 
            64 int
            65 main(int argc, char **argv)
            66 {
            67     while(scanf("%s", input) != EOF) {
            68         if(strcmp(input, "-1"== 0)
            69             break;
            70         memset(inv, 0sizeof(inv));
            71         solve();
            72     }
            73 }

            posted on 2010-10-31 20:19 simplyzhao 閱讀(245) 評論(0)  編輯 收藏 引用 所屬分類: G_其他

            導航

            <2010年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            办公室久久精品| 久久天堂AV综合合色蜜桃网| 99热精品久久只有精品| 国产高清美女一级a毛片久久w| 欧美日韩精品久久久久| 久久精品国产亚洲av麻豆蜜芽| 无码任你躁久久久久久| 久久久久国色AV免费看图片| 亚洲欧美久久久久9999| 精品人妻伦九区久久AAA片69| 精品综合久久久久久888蜜芽| 久久99国产综合精品女同| 99久久成人国产精品免费| 久久AV无码精品人妻糸列| 国产精品九九九久久九九| 久久久综合香蕉尹人综合网| 人妻精品久久无码区| 一级做a爰片久久毛片免费陪| 精品九九久久国内精品| 久久人人妻人人爽人人爽| 伊人久久大香线蕉精品| 久久久久av无码免费网| 日韩精品久久久久久| 99久久精品国产一区二区三区| 中文无码久久精品| 久久久久亚洲AV综合波多野结衣| 久久久国产精品亚洲一区| 久久久精品波多野结衣| 777久久精品一区二区三区无码| 久久久女人与动物群交毛片| 伊人久久无码精品中文字幕| 久久国产精品波多野结衣AV| 久久91综合国产91久久精品| 久久精品国产亚洲77777| 久久这里只有精品18| 国产三级久久久精品麻豆三级| 久久亚洲AV成人无码国产| 综合人妻久久一区二区精品| 亚洲精品无码久久久久sm| 国产V亚洲V天堂无码久久久| 久久久噜噜噜久久熟女AA片|