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 阅读(1355) | 评论 (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 阅读(138) | 评论 (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 阅读(129) | 评论 (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 阅读(218) | 评论 (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 阅读(137) | 评论 (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 阅读(240) | 评论 (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 阅读(168) | 评论 (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 阅读(191) | 评论 (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 阅读(94) | 评论 (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 阅读(150) | 评论 (0)编辑 收藏

仅列出标题
共10页: First 2 3 4 5 6 7 8 9 10