• <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麻豆| 国产精品永久久久久久久久久| 亚洲成色999久久网站| 中文字幕无码免费久久| 亚洲午夜无码久久久久小说| 久久精品国产亚洲AV无码麻豆 | 久久精品国产亚洲av麻豆图片 | 亚洲伊人久久大香线蕉综合图片| 久久亚洲中文字幕精品一区四 | 国产精品日韩深夜福利久久| 色婷婷久久综合中文久久蜜桃av| 久久精品久久久久观看99水蜜桃| 国产aⅴ激情无码久久| 日韩精品久久久久久免费| 亚洲∧v久久久无码精品| 久久久久久久久无码精品亚洲日韩 | 伊人色综合久久天天| 国产精品内射久久久久欢欢 | 爱做久久久久久| 综合久久国产九一剧情麻豆| 久久久久久免费视频| 国产精品对白刺激久久久| 韩国三级中文字幕hd久久精品| 亚洲精品无码久久不卡| 久久亚洲春色中文字幕久久久| 久久精品免费一区二区三区| 91精品国产色综久久| 久久午夜夜伦鲁鲁片免费无码影视| 亚洲va久久久噜噜噜久久狠狠| 国产精品久久久久影院嫩草| 久久精品麻豆日日躁夜夜躁| 久久99中文字幕久久| 伊人久久大香线蕉综合热线| 精品人妻伦九区久久AAA片69| 狠狠色丁香久久婷婷综| 久久精品一区二区三区AV| 99久久精品免费国产大片| 久久精品毛片免费观看| 久久久精品国产亚洲成人满18免费网站 | 97精品久久天干天天天按摩| 9999国产精品欧美久久久久久|