• <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年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            人妻无码αv中文字幕久久 | 久久精品国产秦先生| 欧美熟妇另类久久久久久不卡| 亚洲午夜久久久久久久久电影网| 久久亚洲日韩精品一区二区三区 | 久久久久亚洲精品无码网址| 久久久久一级精品亚洲国产成人综合AV区 | 94久久国产乱子伦精品免费| 精品久久国产一区二区三区香蕉| 久久国产精品无码网站| 久久精品国产精品亚洲精品 | 欧美日韩成人精品久久久免费看| 伊人伊成久久人综合网777| 久久人人爽爽爽人久久久| 国产99久久久国产精品~~牛| 精品国产乱码久久久久软件| 久久男人Av资源网站无码软件| 午夜精品久久久久久久无码| 99国产欧美久久久精品蜜芽| 亚洲精品美女久久久久99小说| 99精品久久精品一区二区| 亚洲精品视频久久久| 久久精品视频91| 91久久精品91久久性色| 亚洲第一极品精品无码久久| 久久国产香蕉视频| 亚洲午夜久久久精品影院| 久久久久久久亚洲Av无码| 伊人久久大香线蕉av不卡| 久久久久黑人强伦姧人妻| A级毛片无码久久精品免费| 国内精品久久久人妻中文字幕| 国产aⅴ激情无码久久| 一本综合久久国产二区| 久久99精品九九九久久婷婷| 国产精品嫩草影院久久| 青青草国产精品久久久久| 久久久久久免费一区二区三区| 国产精品天天影视久久综合网| 国内精品人妻无码久久久影院| 99久久99久久久精品齐齐|