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

            導(dǎo)航

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

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久99久久成人免费播放| 少妇内射兰兰久久| 青青青国产成人久久111网站| 中文字幕无码精品亚洲资源网久久| 久久综合色区| 久久久久久毛片免费看| 国产精品成人久久久久久久| 99久久久精品免费观看国产| 久久久久国产精品熟女影院| 漂亮人妻被黑人久久精品| 精品国产99久久久久久麻豆| 国产精品99久久久精品无码| 久久午夜夜伦鲁鲁片免费无码影视| 香蕉99久久国产综合精品宅男自 | 国产999精品久久久久久| 久久国产一区二区| 丁香久久婷婷国产午夜视频| 久久国产视频99电影| 亚洲国产精品综合久久网络| 欧美粉嫩小泬久久久久久久| 欧美色综合久久久久久| 久久国内免费视频| 久久久一本精品99久久精品66| 久久久久高潮毛片免费全部播放| 99精品久久精品| 久久久久婷婷| 国色天香久久久久久久小说| 久久精品国产亚洲AV麻豆网站 | 久久人人爽人人爽人人片AV麻豆| 色综合久久中文字幕综合网| 国产精品久久久久久久午夜片 | 久久精品国产亚洲AV不卡| 人人狠狠综合久久88成人| 久久精品成人国产午夜| 久久久久亚洲AV成人网人人网站| 久久久久亚洲国产| 2021少妇久久久久久久久久| 日韩中文久久| 国产69精品久久久久777| 久久精品国产一区二区三区| 久久亚洲精品成人无码网站|