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

            #

             鐵軌

            PopPush城市有一座著名的火車站。這個國家到處都是丘陵。而這個火車站是建于上一個世紀。不幸的是,那時的資金有限。所以只能建立起一條路面鐵軌。而且,這導致這個火車站在同一個時刻只能一個軌道投入使用,因為它缺少空間,兩列火車將無路可走。具體看下圖。

            當地的慣例是每一列火車從A方向駛向B方向時候,會用某種方式將車廂重組。假設火車將要到達A方向,擁有N個車廂(N<=1000),這些車廂按照遞增順序標記為1到N。負責從組車廂的領導,必須知道是否能從組車廂讓它駛出B,而這個重組的序列就是a1\a2\a3...aN.幫組他并且寫一個程序來判斷是否可能按照所要求的車廂順序。你可以假設,單個的車廂可以從列車上分離出來,在他們進入站臺之前。并且他們可以自由移動,知道它們上了B軌道。你也可以假設在任意時候站臺可以放下無數的車廂。但是只要一個車廂進入站臺,它就不能返回A軌道,同時如果它離開了站臺駛向B軌道,它就不能返回站臺。

            輸入:
            這個輸入文件由多個行塊組成。每一個塊描述的是多個要求的重組車廂的序列。在這每個塊中的第一行是一個整數N,被用來說明上面每行的車廂個數。這個快的最后一行僅僅是一個數字0要來標記該快的結束
            最后一個塊僅僅是一個0獨占一行。

            輸出:
            這個輸出文件包含多行,這些行和排列車廂的行數一一對應。日過該排列可行,則輸出Yes,否則輸出No。另外存在一個空行在每個相對應的塊后面。輸出文件中不存在于最后一個什么數據都沒有的響應輸出。

            輸出
            5
            1 2 3 4 5
            5 4 1 2 3
            0
            6
            6 5 4 3 2 1
            0
            0

            Output
            Yes
            No

            Yes

             1 /*
             2 由于station符合后進先出規則,所以可以用一個stack<int>來表示station。
             3 然后采用模擬的規則來寫,因為進入station是按照編號遞增進入,所以可以用aId變量表示。
             4 接下來就是模擬時候應該注意的條件,我們知道有以下兩種情況,一種是一進來station,就出station
             5 也就是 aId == coaches[lenB]; 一種是進來時還不出站,那么這時候就要s.push(aId),但是這一種的條件呢?
             6 我們如果可以排除掉第一種,那么無非就是第二種了。但是我們要知道,在進站之前,如果站臺里有車它是可以先出站的
             7 ,這種狀態就條件就是 !s.empty() && s.top() == coaches[lenB].所以只要按照順序判斷這幾個條件
             8 就可以寫出這個模擬程序了。
             9 
            10 
            11 總結:
            12 解決問題的關鍵點,在于構建問題的模型、大部分都是可以用現有的基礎數據結構。構造完對應的數據結構,特別是對于模擬題
            13 無非就是狀態見的轉移處理,這是就要在基于模型的基礎上、先寫出映射到個個狀態的唯一條件,然后按照問題邏輯一一先后判斷
            14 即可。
            15 */
            16 #include <iostream>
            17 #include <stack>
            18 
            19 using namespace std;
            20 const int len = 1024;
            21 int coaches[len];
            22 
            23 int main() {
            24 
            25     int n;
            26     while (cin >> n, n) { 
            27         stack<int> s;
            28         // read the required permutaion
            29 
            30         while (    cin >> coaches[0], coaches[0]) {
            31 
            32             for (int i = 1; i < n; i++) {
            33                 cin >> coaches[i];
            34             }
            35             int lenB = 0, aId = 1;
            36             bool ok = true;
            37             while (lenB < n) {
            38 
            39                 if (aId == coaches[lenB]) {  aId++; lenB++; }
            40                 else if(!s.empty() && s.top() == coaches[lenB]) { s.pop(); lenB++; }
            41                 else if(aId <= n) s.push(aId++);
            42                 else { ok = falsebreak; }
            43 
            44             }
            45 
            46             cout << (ok ? "Yes" : "No") << endl;
            47         }
            48         cout << endl;
            49     }
            50     
            51     return 0;
            52 }
            2015/3/30下午3:03:52
            posted @ 2015-03-30 16:17 swp 閱讀(1389) | 評論 (0)編輯 收藏

            題目其實很簡單,答題意思就是從管道讀取一組文件名,并且按照字典序排列,但是輸入的時候按列先輸出,再輸出行。而且每一行最多60個字符。而每個文件名所占的寬度為最大文件名的長度加2,除了輸出在最右邊的文件名的寬度是最大文件名長度之外。編程實現這個功能,這就是Unix系統下ls命令的一部分而已。具體實現如下。
            主要學習的技能要點就是如何用偏移位移法來按列輸出。如果一個矩陣n行m列,要按照列輸出。但是我們知道,編程時候,只能是for(行)在列。所以必須要有一個偏移量來計算這種偏移關系。x = rows * c + r;

             1 #include <iostream>
             2 #include <string>
             3 #include <algorithm>
             4 #include <vector>
             5 #include <cmath>
             6 
             7 using namespace std;
             8 
             9 vector<string> words;
            10 void print(const string &s, int len, char extra);
            11 int main() {
            12     
            13     
            14     int n;
            15     string w;
            16     
            17     while (cin >> n) {
            18         
            19         int max = 0;
            20         words.clear();
            21         for (int i = 0; i < n; i++) {
            22             cin >> w;
            23             string::size_type str_size = w.size();
            24             if (str_size > max) max = str_size;
            25             words.push_back(w);
            26         }
            27         int cols = (60 - max) / (max + 2) + 1;
            28         int rows = ceil(double(n) / cols);
            29         sort(words.begin(), words.end());
            30         print("", 60, '-');
            31         cout << endl;
            32         for(int r = 0; r < rows; r++) {
            33             
            34             for (int c = 0; c < cols; c++) {
            35                 
            36                 int idx = c * rows + r;
            37                 if (idx < n) print(words[idx],(c == cols - 1? max: max + 2), ' ');
            38                 
            39             }
            40             
            41             cout << endl;
            42             
            43         }
            44         
            45         
            46     }
            47     
            48     return 0;
            49     
            50 }
            51 
            52 void print(const string &s, int len, char extra) {
            53     
            54     cout << s;
            55     string::size_type str_size = s.size();
            56     for (int i = 0; i < len - str_size; i++) {
            57         cout << extra;
            58     }
            59 }
            posted @ 2015-03-25 14:32 swp 閱讀(159) | 評論 (0)編輯 收藏

             1 #include <iostream>
             2 #include <string>
             3 #include <algorithm>
             4 #include <map>
             5 #include <vector>
             6 using namespace std;
             7 
             8 map<stringint> cnt;
             9 vector<string> words;
            10 
            11 string formatWord(const string &s);
            12 
            13 int main() {
            14     
            15     string s;
            16     while(cin >> s) {
            17         
            18         if (s[0] == '#') break;
            19         words.push_back(s);
            20         
            21         string fw = formatWord(s);
            22         if (!cnt.count(fw)) cnt[fw] = 0;
            23         cnt[fw]++;
            24     }
            25     
            26     vector<string> ans;
            27     for (int i = 0; i < words.size(); i++) {
            28         
            29         if ( cnt[formatWord( words[i] ) ] == 1) ans.push_back(words[i]);
            30     }
            31     
            32     sort(ans.begin(), ans.end());
            33     for (int i = 0; i < ans.size(); i++) {
            34         cout << ans[i] << endl;
            35     }
            36     return 0;
            37 }
            38 
            39 string formatWord(const string &s) {
            40     
            41     string ans = s;
            42     int str_size = ans.size();
            43     for (int i = 0; i <str_size; i++) {
            44         
            45         ans[i] = tolower(ans[i]);
            46         
            47     }
            48     sort(ans.begin(), ans.end());
            49     return ans;
            50 
            51 }
            posted @ 2015-03-24 17:13 swp 閱讀(155) | 評論 (0)編輯 收藏

            這道題目、主要是對隊列的靈活應用。其實就是一道模擬題目,只要你洞察出題目的本質就十分簡單。題目意思大體是有多組測試數據,每組的一開始是一個數字t,代表一共有多少的團隊,接著是t行輸入,每一行都由一個數字n開頭,表示隊伍的人數。在這之后,輸入諾干行的操作指令,E x代表入編號為x的入隊列,這里的隊列是一個新的而且只有一個的新隊列。D代表就是出隊列、同時輸出該元素、S表示停止模擬。
            題目的具體要求是,每次入隊里前,先從隊列頭掃描到隊列尾,如果隊列里有隊友,就排在隊友們的最后面(不是該隊友的后面,是整隊隊友的最后面)。如果沒有隊友則,直接排在隊列的最后面。出隊列的沒什么特別的了。

            Keys:其實我們可以通過簡單的模擬、發現。由第一個隊員到最后一個隊員入隊列,或者中間有其他出隊列。該隊列始終可以看成是兩個隊列的隊列。又因為題目要求常數的時間、
            所以我們不可能把時間浪費在某個隊員屬于哪一個隊里,所以可以用映射、也就是map來解決這個問題。map<int, int>這個結構剛好能映射這種關系。接下去就是要有一個q2[maxn]來表示所有初始化的隊列。一個q來表示新隊列,這個q其實就是隊列的隊列。

             1 #include <queue>
             2 #include <string>
             3 #include <map>
             4 #include <iostream>
             5 using namespace std;
             6 
             7 const int maxn = 1024;
             8 
             9 
            10 int main() {
            11     
            12     int t, n, k = 0;
            13     while (cin >> t, t) {
            14         // 列隊編號
            15         cout << "Scenario #" << ++k << endl;
            16         int qid = 1;
            17         map<intint> team;
            18         while (t--) {
            19             cin >> n;
            20             for (int i = 0; i < n; i++) {
            21                 int uid;
            22                 cin >> uid;
            23                 team[uid] = qid;
            24                 
            25             }
            26             qid++;
            27         }
            28         
            29         // uid是隊員編號、 tid是那一對隊的編號
            30         queue<int> q,q2[maxn];
            31         string op;
            32         int uid;
            33         
            34         while (cin >> op, op[0] != 'S') {
            35             
            36             // 入隊列
            37             if ('E' == op[0]) {
            38                 cin >> uid;
            39                 int tid = team[uid];
            40                 if (q2[tid].empty()) q.push(tid);
            41                 q2[tid].push(uid);
            42 
            43             }
            44             // 出隊列
            45             if ('D' == op[0]) {
            46                 
            47                 int tid = q.front();
            48                 int x = q2[tid].front();
            49                 q2[tid].pop();
            50                 cout << x << endl;
            51                 if (q2[tid].empty()) q.pop();
            52                 
            53             }
            54             
            55         }
            56         
            57         cout << endl;
            58         
            59     
            60     }
            61     
            62 }
            posted @ 2015-03-24 08:31 swp 閱讀(237) | 評論 (0)編輯 收藏

             1 #include <set>
             2 #include <string>
             3 #include <vector>
             4 #include <map>
             5 #include <stack>
             6 #include <iostream>
             7 #include <algorithm>
             8 #define ALL(x) x.begin(), x.end()
             9 #define INS(x) inserter(x, x.begin())
            10 
            11 using namespace std;
            12 
            13 typedef set<int> Set;
            14 map<Set, int> IDCache;
            15 vector<Set> Setcache;
            16 // 主要的想法是能想到用map<set<int>, int>這種數據結構來把集合映射成整數
            17 // 關鍵實現在ID函數,對于給定的set<int>都能返回一個唯一編號、vector雖然不能保證元素的唯一性。
            18 // 但是我們可以先對map進行檢查來保證vector中元素的唯一性,這樣每個元素就能唯一編號,剛好可以利用他們的整數索引。
            19 // 其中set_union、set_intersection中得實現原理不是重點,先學會怎么用才是重點。
            20 // ID函數實現了對新的集合存儲,并且
            21 int ID(Set x);
            22 int main() {
            23 
            24     
            25     stack<int> s;
            26     int t, n;
            27     string op;
            28     cin >> t;
            29     while (t--) {
            30         cin >> n;
            31         IDCache.clear();
            32         Setcache.clear();
            33         for (int i = 0; i < n; i++) {
            34 
            35             cin >> op;
            36             if (op[0] == 'P') s.push(ID(Set())); // Set()就是空集
            37             else if(op[0] == 'D') s.push(s.top());
            38             else {
            39                 
            40                 Set x1 = Setcache[s.top()]; s.pop();
            41                 Set x2 = Setcache[s.top()]; s.pop();
            42                 Set x;
            43                 if (op[0] == 'U') set_union (ALL(x1), ALL(x2), INS(x));
            44                 if (op[0] == 'I') set_intersection (ALL(x1), ALL(x2), INS(x));
            45                 if (op[0] == 'A') { x = x2; x.insert(ID(x1)); }
            46                 s.push(ID(x));
            47                 
            48             }
            49             
            50             cout << Setcache[s.top()].size() << endl;
            51         }
            52         cout << "***" << endl;
            53     
            54     }
            55     return 0;
            56 }
            57 
            58 // 相當于數據庫中得auto_increment, 返回一個唯一的ID值
            59 int ID(Set x) {
            60     
            61     if (IDCache.count(x)) return IDCache[x];
            62     Setcache.push_back(x);
            63     return IDCache[x] = Setcache.size() - 1;
            64 
            65 }
            posted @ 2015-03-23 22:29 swp 閱讀(166) | 評論 (0)編輯 收藏

            題目很簡單。其實stringstream就的用法和iosteam差不多,所以學習起來是很簡單的。stringstream類里面有一個string緩存,str()和str(string)成員函數。
            前者用于把stringstream的返回string緩存,后者是把string對象包裝成stringstream對象。stringstream類存在于sstream頭文件中。其是獨立于標準I/O但有類似
            功能的類。clear主要是為了多次使用stringstream,因為stringstream每次的構造都十分耗時,所以最后能多次,反復使用,就如同面向對象里面的單例模式。
            代碼如下:
             1 #include <iostream>
             2 #include <string>
             3 #include <set>
             4 #include <sstream>
             5 
             6 
             7 using namespace std;
             8 
             9 set<string> dict;
            10 stringstream ss;
            11 
            12 /*
            13  主要學習兩個重點stringstream的用法與set容器的insert、迭代器的用法。
            14  */
            15 int main() {
            16 
            17     string s,buf;
            18     
            19     while (cin >> s) {
            20         int len = s.size();
            21         for (int i = 0; i < len; i++) {
            22             if (isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' ';
            23         }
            24         ss.clear();
            25         ss.str(s);
            26         while (ss >> buf) dict.insert(buf);
            27     }
            28     
            29     for (set<string>::iterator it = dict.begin(); it != dict.end(); ++it)
            30         cout << *it << endl;
            31     return 0;
            32 }
            posted @ 2015-03-16 18:28 swp 閱讀(260) | 評論 (0)編輯 收藏

            這是一道很好的模擬題,用vector<int> p[maxn],建立模型,映射為maxn個堆。主要要掌握vector模擬堆操作的簡單方法。
            接下來得思路是自頂向下的方式,逐步完善程序。首先根據提議列出下表。
            1.move a onto b
            clear_above(a) && clear_above(b);
            insert a above b;

            2.move a over b
            clear(a)
            insert a above bs

            3.pile a onto b
            clear(b)
            insert as above b

            4.pile a over b
            insert as above bs

            觀察可以提取出move的話必有clear_above(a)、onto必有clear_above(b).
            而insert 動作不管b是在p[b]的頂部還是外部。都是p[b].push_back(a或a以上的木塊)
            所以可以抽取成pile_into(pa, ha, pb);

            考慮完這些,開始寫框架。如下
             1 
             2 #include <cstdio>
             3 #include <iostream>
             4 #include <string>
             5 #include <vector>
             6 using namespace std;
             7 
             8 const int maxn = 64;
             9 int n;
            10 vector<int> a[maxn];
            11 int find_block(int a, int& h);
            12 void clear_above(int p, int h);
            13 void pile_into(int pa, int ha, int pb);
            14 void print();
            15 int main() {
            16 
            17     
            18     
            19     string s1, s2;
            20     scanf("%d", &n);
            21     for (int i = 0; i < n ; i++) {
            22         a[i].push_back(i);
            23     }
            24     
            25     while (cin >> s1, s1 != "quit") {
            26         int ba,bb;
            27         cin >> ba >> s2 >> bb;
            28         int ha = 0,hb = 0;
            29         int pa = find_block(ba, ha);
            30         int pb = find_block(bb, hb);
            31         if (pa == pb) continue;
            32         
            33         if (s1 == "move") clear_above(pa, ha);
            34         if (s2 == "onto") clear_above(pb, hb);
            35         pile_into(pa, ha, pb);
            36     }
            37     
            38     print();
            39     return 0;
            40 }
             
            接下來,完成程序其它部分,按照框架的意思,逐步完善。如下
             1 void print() {
             2     
             3     for (int i = 0; i < n; i++) {
             4         printf("%d:",i);
             5         for (int h = 0; h < a[i].size(); h++) {
             6             printf(" %d", a[i][h]);
             7         }
             8         printf("\n");
             9     }
            10 }
            11 
            12 int find_block(int ba, int& h) { 
            13     
            14     for (int i = 0; i < n; i++) {
            15         
            16         int vec_size = a[i].size();
            17         for (h = 0; h < vec_size; h++) {
            18             if (ba == a[i][h]) return i;
            19         }
            20         
            21     }
            22     return -1;
            23 }
            24 
            25 void clear_above(int p, int h) {
            26     int vec_size = a[p].size();
            27     for (int i = h + 1; i < vec_size; i++) {
            28         
            29         int b = a[p][i];
            30         a[b].push_back(b);
            31         
            32     }
            33     a[p].resize(h + 1);
            34 }
            35 
            36 void pile_into(int pa, int ha, int pb) {
            37     
            38     int vec_size = a[pa].size();
            39     
            40     for (int i = ha; i < vec_size; i++) {
            41         a[pb].push_back(a[pa][i]);
            42     }
            43     a[pa].resize(ha);
            44 }
            posted @ 2015-03-16 15:03 swp 閱讀(205) | 評論 (0)編輯 收藏

            坑爹的模擬題目。自己對于這種比較復雜點得模擬題的能力概述還不夠,還多加練習。貼別是做得時候一直再想如何檢查車中間有沒有棋子,炮中間有沒有棋子。到網上參考別人的代碼才發先這么簡單的辦法,自己盡然想不到。多加練習,總結下該題目吧。
              1 #include <stdio.h>
              2 #include <string.h>
              3 #define N 12
              4 
              5 char brd[N][N];
              6 int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};
              7 int hx[] = {-2,-1,-2,-1,1,2,1,2};
              8 int hy[] = {-1,-2,1,2,-2,-1,2,1};
              9 int tx[] = {-1,-1,-1,-1,1,1,1,1};
             10 int ty[] = {-1,-1,1,1,-1,-1,1,1};
             11 int cr[2], cc[2];
             12 
             13 
             14 int check(intint);
             15 
             16 int main() {
             17     
             18     int t, bX, bY;
             19     char s[5];
             20     while (scanf("%d%d%d",&t, &bX, &bY), t || bX || bY) {
             21         
             22         memset(brd, 0, sizeof(brd));
             23         cr[0] = cc[0] = cr[1] = cc[1] = 0;
             24         
             25         for (int i = 0; i < t; i++) {
             26             
             27             int rX, rY;
             28             scanf("%s%d%d", s, &rX, &rY);
             29             if ('C' == s[0]) {
             30                 
             31                 if (cr[0]) cr[1] = rX, cc[1] = rY;
             32                 else cr[0] = rX, cc[0] = rY;
             33             }
             34             brd[rX][rY] = s[0];
             35         }
             36         
             37         // 判斷是否四個方向都會被將軍,或者無路可走的方向也認為是被將軍
             38         int cnt = 0;
             39         for (int i = 0; i < 4; i++)
             40             cnt += check(bX + dx[i], bY + dy[i]);
             41         
             42         if (cnt < 4) puts("NO");
             43         else puts("YES");
             44         
             45     }
             46     
             47 }
             48 
             49 int check(int r, int c) {
             50     
             51     // 越界,無路可走
             52     if (r < 1 || r > 3 || c < 4 || c > 6) return 1;
             53     
             54     
             55     // 因為我們沒法保證車中間有沒有其他棋子,所以必須從近到遠一格格檢查
             56     // 車在同行且中間無棋子
             57     for (int j = c - 1; j > 0; j--) {
             58         if (brd[r][j])
             59             if ('R' == brd[r][j]) return 1;
             60             else break;
             61     }
             62     
             63     for (int j = c + 1; j <= 9; j++) {
             64         
             65         if (brd[r][j])
             66             if ('R' == brd[r][j]) return 1;
             67             else break;
             68     }
             69     
             70     
             71     // 車在同列且中間物棋子
             72     for (int j = r - 1; j > 0; j--) {
             73         
             74         if (brd[j][c])
             75             if ('R' == brd[j][c]) return 1;
             76             else break;
             77         
             78     }
             79     
             80     for (int j = r + 1; j <=10; j++) {
             81         
             82         if (brd[j][c])
             83             if ('R' == brd[j][c] || 'G' == brd[j][c]) return 1;
             84             else break;
             85         
             86     }
             87     
             88     // 炮將軍
             89     for (int k = 0; k < 2; k++) {
             90         
             91         // 行有炮
             92         if (r == cr[k]) {
             93             int cnt = 0;
             94             for (int j = c - 1; j > cc[k]; j--) if (brd[r][j]) ++cnt;
             95             if (cnt == 1) return 1;
             96             cnt = 0;
             97             for (int j = c + 1; j < cc[k]; j++) if (brd[r][j]) ++cnt;
             98             if (cnt == 1) return 1;
             99             
            100         }
            101         
            102         // 列有跑
            103         if (c == cc[k]) {
            104             int cnt = 0;
            105             for (int j = r - 1; j > cr[k]; j--) if (brd[j][c]) ++cnt;
            106             if (cnt == 1) return 1;
            107             cnt = 0;
            108             for (int j = r + 1; j < cr[k]; j++) if (brd[j][c]) ++cnt;
            109             if (cnt == 1) return 1;
            110         }
            111         
            112         
            113     }
            114     
            115     // 馬將軍,馬的8個方位
            116     for(int k = 0; k < 8; ++k) {
            117         
            118         int tr = r + hx[k], tc = c + hy[k];
            119         if (tr < 1 || tr > 10 || tc < 1 || tc > 9) continue;
            120         if (brd[tr][tc] == 'H' && (!brd[r + tx[k]][c + ty[k]]))
            121             return 1;
            122         
            123     }
            124     return 0;
            125 }
            posted @ 2015-03-15 16:42 swp 閱讀(213) | 評論 (0)編輯 收藏

             1 #include <stdio.h>
             2 
             3 #define MAXN 1024
             4 char buf[MAXN] = {0};
             5 int main() {
             6 
             7     FILE *fp = fopen("t.txt","r");
             8     if (!fp) return -1;
             9 
            10     for (;;) {
            11         
            12         char * p = fgets(buf, MAXN, fp);
            13         if (!p) break;
            14         printf("%s",p);
            15     }
            16     fclose(fp);
            17     return 0;
            18 }
            19 /*之所以用fgets是因為fscanf有scanf的特性,遇到空白符就會終止讀取。所以要讀取一行最好是用fgets函數。該函數第一個是char buf[maxn]的數組名稱buf,第二個是maxn,最多能存下maxn-1個字符,最后一個是'\0'。
            20 該函數遇到換行符號停止讀取
            21 */
             1 #include <stdio.h>
             2 
             3 void print(int *intint);
             4 int main() {
             5 
             6     
             7     int a[] = {12345678910};
             8     int t = 10;
             9     // 枚舉起始位置
            10     for (int p = 0;; p -= 2) {
            11         
            12         print(a, t, p);
            13         if (p != 0 && ((p + t) % t) == 0break// 重復則退出
            14     }
            15     return 0;
            16 }
            17 
            18 // 輸出一個環,該環的初始位置為p,周期為t
            19 void print(int *a, int t, int p) {
            20     
            21     for (int i = 0; i < 10; i++) {
            22         p = (p + t) % t;
            23         printf("%d ", a[p]);
            24         p++;
            25         
            26     }
            27     putchar('\n');
            28 }
            29 
            30 //該帖子地址http://bbs.bccn.net/thread-442590-1-1.html

            about me,copy the url to your brower~.
            http://bbs.bccn.net/space-uid-814155.html
            posted @ 2015-03-13 21:23 swp 閱讀(109) | 評論 (0)編輯 收藏

             1 #include <stdio.h>
             2 #include <string.h>
             3 
             4 
             5 int readChar();
             6 int readInt(int c);
             7 int readCodes();
             8 
             9 /*
            10  1.讀取字符時候如何過濾掉換行符號,兼容類unix和windows操作系統 readChar()
            11  2.熟練掌握將二進制字符串映射到數組的數據結構,這個數據結構是個二元組,我們可以用該二元組唯一確定一個長度為len的二進制字符串
            12  (len, value) ---- > code[len][value]
            13  
            14  */
            15 
            16 int main() {
            17 
            18     
            19     while ( readCodes() ) { // 讀編碼頭
            20         
            21         for (;;) {  // 讀信息
            22             
            23             int len = readInt(3);
            24             if (0 == len) break// 全0該信息結束
            25             
            26             for (;;) {  // 讀信息段
            27                 
            28                 int v = readInt(len);
            29                 
            30                 if (v == (1 << len) - 1break// 全1一個信息段結束
            31                 putchar(code[len][v]);
            32                 
            33             }
            34             
            35         }
            36         
            37         putchar('\n');
            38     }
            39 }
            40 
            41 
            42 int readInt(int l) {
            43     
            44     int v = 0;
            45     //已經讀取了3 - l個字符
            46     while (l--) {
            47         
            48         v = v * 2 + readChar() - '0';
            49         
            50     }
            51     return v;
            52     
            53 }
            54 
            55 
            56 char readChar() {
            57     
            58     char ch;
            59     do {
            60         
            61         ch = getchar();
            62         
            63     }while ( '\n' != ch || '\r' != ch )
            64     return ch;
            65 }
            66 
            67 
            68 int readCodes() {
            69     
            70     
            71     memset(code, 0sizeof(code));
            72     
            73     // 因為可能讀取編碼頭獨占一行,所以我們可能讀取編碼頭時候會讀取到上一次的回車換行,所以要使用readChar函數
            74     code[1][0= readChar();
            75     
            76     for (int len = 2; len < 8; len++) {
            77         
            78         for (int v = 0; v < (1 << len) - 1; v++) {
            79             
            80             char ch = getchar();
            81             if ( EOF == ch ) return 0;
            82             if ( '\n' == ch || '\r' == ch) return 1;
            83             code[len][v] = ch;
            84             
            85         }
            86         
            87     }
            88     return 1;
            89     
            90     
            91 }
            posted @ 2015-03-13 20:06 swp 閱讀(177) | 評論 (0)編輯 收藏

            僅列出標題
            共10頁: First 2 3 4 5 6 7 8 9 10 
            久久九色综合九色99伊人| 久久―日本道色综合久久| 久久www免费人成看片| 久久永久免费人妻精品下载| 精品无码久久久久久尤物| 99久久精品费精品国产 | 亚洲精品成人久久久| 久久精品久久久久观看99水蜜桃| 久久精品中文闷骚内射| 精品久久久久久无码中文字幕 | 久久夜色撩人精品国产| 7777久久久国产精品消防器材| 狠狠色噜噜狠狠狠狠狠色综合久久 | 人妻精品久久久久中文字幕一冢本| 91精品国产高清91久久久久久| 久久久久国色AV免费观看| 久久久老熟女一区二区三区| 久久久WWW免费人成精品| 精品无码久久久久久午夜| 久久人人青草97香蕉| 久久国产精品国产自线拍免费| 久久中文字幕精品| 99久久国产亚洲高清观看2024| 亚洲中文精品久久久久久不卡| 久久99久久无码毛片一区二区| 精品免费久久久久久久| 久久无码高潮喷水| 久久婷婷五月综合97色直播| 久久精品国产半推半就| 亚洲AV无码久久精品色欲| 热久久视久久精品18| 国产午夜电影久久| 天天综合久久久网| av国内精品久久久久影院| 无遮挡粉嫩小泬久久久久久久 | 久久国产亚洲精品| 亚洲成av人片不卡无码久久| 久久精品国产色蜜蜜麻豆 | 精品久久久无码人妻中文字幕| 香蕉99久久国产综合精品宅男自 | 久久99久久无码毛片一区二区|