• <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 閱讀(244) 評論(0)  編輯 收藏 引用 所屬分類: G_其他

            導航

            <2011年5月>
            24252627282930
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品不卡| 无码专区久久综合久中文字幕 | 亚洲AV日韩精品久久久久久| 久久久久精品国产亚洲AV无码| 人妻系列无码专区久久五月天| 久久人人青草97香蕉| 粉嫩小泬无遮挡久久久久久| 激情五月综合综合久久69| 久久人妻AV中文字幕| 91久久精品国产91性色也| 精品久久久久久久国产潘金莲 | 国产精品欧美亚洲韩国日本久久| 亚洲AV伊人久久青青草原| 久久99精品久久久久久动态图| 久久国产热这里只有精品| 日本欧美久久久久免费播放网| 午夜不卡888久久| 亚洲AV日韩精品久久久久| 久久精品三级视频| 精品精品国产自在久久高清| 久久久久久国产精品美女| 日韩电影久久久被窝网| 日本免费久久久久久久网站| 欧洲成人午夜精品无码区久久| 久久久久久久国产免费看| 久久精品九九亚洲精品天堂| 久久亚洲国产成人精品性色| 久久精品久久久久观看99水蜜桃| 久久久精品日本一区二区三区| 久久久久久a亚洲欧洲aⅴ| 国产精品岛国久久久久| 久久国产精品成人影院| 日产精品久久久久久久| 亚洲第一极品精品无码久久| 亚洲国产日韩欧美久久| 亚洲人成网站999久久久综合| 久久精品国产99久久久香蕉 | 思思久久好好热精品国产| 久久久99精品成人片中文字幕 | 污污内射久久一区二区欧美日韩 | 国产产无码乱码精品久久鸭 |