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

            f(sixleaves) = sixleaves

            重劍無鋒 大巧不工

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              95 隨筆 :: 0 文章 :: 7 評論 :: 0 Trackbacks
            這道題目略坑,如果用模擬來做的話,其實很簡單,一開始想的是模擬之后覺得集合更簡答,但是忽略了一點是,用集合來做的話,集合是無序的,但是題目中得輸入順序是有序的。而且用模擬的時間復雜度為O(n^2).

             1 #include <stdio.h>
             2 #include <string.h>
             3 #define MAXN 1024
             4 
             5 int left, chance;
             6 int win, lose;
             7 void guess(char ch);
             8 
             9 char p[MAXN] = {0}, g[MAXN] = {0};
            10 int main() {
            11     
            12     int r = 0;
            13     
            14     while (scanf("%d%s%s",&r, p, g) == 3 && r != -1) {
            15         
            16         printf("Round %d\n", r);
            17         win = lose = 0;
            18         left = strlen(p);
            19         chance = 7;
            20         for (int i = 0; g[i]; i++) {
            21             
            22             guess(g[i]);
            23             
            24             if (win || lose) break;
            25             
            26         }
            27         
            28         if (win) printf("You win.\n");
            29         else if(lose) printf("You lose.\n");
            30         else printf("You chickened out.\n");
            31         
            32     }
            33     return 0;
            34 }
            35 
            36 
            37 void guess(char ch) {
            38     
            39     int finded = 0;
            40     for (int i = 0; p[i]; i++) {
            41         
            42         if (ch == p[i]) {
            43             p[i] = ' ';
            44             left--;
            45             finded = 1;
            46             
            47         }
            48         
            49     }
            50     
            51     if (!finded) --chance;
            52     if (!chance) lose = 1;
            53     if (!left) win = 1;
            54     
            55 }

            by sixleaves
            posted on 2015-02-07 13:29 swp 閱讀(150) 評論(0)  編輯 收藏 引用 所屬分類: algorithm
            国产三级久久久精品麻豆三级| 亚洲精品综合久久| 久久九九青青国产精品| 国产精久久一区二区三区| 色综合合久久天天给综看| 久久婷婷五月综合国产尤物app| av无码久久久久不卡免费网站| 色综合久久精品中文字幕首页| 一级a性色生活片久久无| 久久99精品国产99久久| 国产精品久久新婚兰兰| 久久最近最新中文字幕大全| 国产成人综合久久精品红| 99久久精品免费看国产免费| 久久午夜夜伦鲁鲁片免费无码影视| 国产精品国色综合久久| 一级女性全黄久久生活片免费 | 国产成人久久精品一区二区三区| 久久久国产精品福利免费| 99久久精品免费看国产一区二区三区| 久久久久久久国产免费看| 麻豆亚洲AV永久无码精品久久| 青青草国产97免久久费观看| 久久久久亚洲?V成人无码| 久久国产精品波多野结衣AV| 久久久WWW成人| 热99re久久国超精品首页| 亚洲综合久久夜AV | 97久久精品人妻人人搡人人玩 | 久久精品国产亚洲AV嫖农村妇女| 久久精品国产亚洲精品| AV无码久久久久不卡蜜桃| 亚洲中文字幕无码久久2017| 久久精品成人一区二区三区| 久久久噜噜噜www成人网| 中文无码久久精品| 97精品伊人久久久大香线蕉| 久久综合视频网站| 久久久久久久亚洲精品| 欧美久久久久久精选9999| 久久精品国产亚洲一区二区三区|