HDU 2700 Parity (水题)
来源:互联网 发布:数学英语词典知乎 编辑:程序博客网 时间:2024/05/18 01:31
传送门:点击打开链接
Parity
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4802 Accepted Submission(s): 3609
Problem Description
A bit string has odd parity if the number of 1's is odd. A bit string has even parity if the number of 1's is even.Zero is considered to be an even number, so a bit string with no 1's has even parity. Note that the number of
0's does not affect the parity of a bit string.
0's does not affect the parity of a bit string.
Input
The input consists of one or more strings, each on a line by itself, followed by a line containing only "#" that signals the end of the input. Each string contains 1–31 bits followed by either a lowercase letter 'e' or a lowercase letter 'o'.
Output
Each line of output must look just like the corresponding line of input, except that the letter at the end is replaced by the correct bit so that the entire bit string has even parity (if the letter was 'e') or odd parity (if the letter was 'o').
Sample Input
101e010010o1e000e110100101o#
Sample Output
101001001011100001101001010
水题不解释。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>using namespace std;int main(){char a[50];int i,j,count;while(cin>>a){getchar();count=0;if(strcmp(a,"#")==0)break;int n=strlen(a);for(i=0;i<n-1;i++){cout<<a[i];if(a[i]=='1'){count++;}}if(a[n-1]=='o'&&count%2==1)cout<<'0'<<endl;else if(a[n-1]=='o'&&count%2==0)cout<<'1'<<endl;else if(a[n-1]=='e'&&(count%2==0))cout<<'0'<<endl;else if(a[n-1]=='e'&&count%2==1)cout<<'1'<<endl;}return 0;}
阅读全文
0 0
- HDU 2700 Parity (水题)
- HDU 2700 Parity(水~)
- HDU 2700 Parity(模拟)
- HDU 2700 Parity(签到)
- hdu 2700 Parity
- HDU 2700 Parity
- HDU 2700 Parity
- HDU 2700 【Implementation】Parity
- HDU-2700-Parity
- Parity HDU 2700
- HDU 2700 Parity
- hdu 2700 Parity
- hdu 2700 Parity
- hdu 2700 parity
- HDU 2700 Parity
- hdu-2700-Parity
- HDU 2700 Parity [Ad Hoc]
- HDU 2700 Parity【字符处理】
- HDU 2124 Repair the Wall(贪心)
- session一致性架构设计
- 文件搜索神器everything 的技巧总结以及关于Archive Searcher搜素压缩包内文件使用
- 测试工程师职业发展
- 超轻巧卸载利器,从此卸载无残留
- HDU 2700 Parity (水题)
- SQL学习笔记2.0
- 隐马尔可夫模型
- Android
- 类对象只能在堆上分配空间的方法
- HDU 2709 Sumsets(递推)
- cc1101 简单入门
- NGUI之组件获取
- Retrofit上传文件