首页 > 其他 > 详细

HDU 2700 Parity

时间:2017-03-18 10:56:17      阅读:192      评论:0      收藏:0      [点我收藏+]

奇偶校验

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #define READ() freopen("in.txt", "r", stdin);
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     //READ()
10     char str[256];
11     while (gets(str))
12     {
13         if (str[0] == #) break;
14         int len = strlen(str);
15         int one = 0, zero = 0;
16         for (int i = 0; i < len; i++)
17         {
18             if (str[i] == 0) zero++;
19             else if (str[i] == 1) one++;
20             else break;
21             putchar(str[i]);
22         }
23         if (str[len-1] == e)
24         {
25             if (one % 2 == 0) puts("0");
26             else puts("1");
27         }
28         else
29         {
30             if (one % 2 == 0) puts("1");
31             else puts("0");
32         }
33     }
34     return 0;
35 }

 

HDU 2700 Parity

原文:http://www.cnblogs.com/oscar-cnblogs/p/6571936.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!