HDU 2700
Parity
Time Limit: 2000/1000 MS(Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4334 Accepted Submission(s): 3264
Problem Description
A bit string hasodd parity if the number of 1's is odd. A bit string has even parity if thenumber of 1's is even.Zero is considered to be an even number, so a bit stringwith no 1's has even parity. Note that the number of
0's does not affect the parity of a bit string.
Input
The input consistsof one or more strings, each on a line by itself, followed by a line containingonly "#" that signals the end of the input. Each string contains 1–31bits followed by either a lowercase letter 'e' or a lowercase letter 'o'.
Output
Each line ofoutput must look just like the corresponding line of input, except that theletter at the end is replaced by the correct bit so that the entire bit stringhas even parity (if the letter was 'e') or odd parity (if the letter was 'o').
Sample Input
101e
010010o
1e
000e
110100101o
#
Sample Output
1010
0100101
11
0000
1101001010
题意简述
看字符串中1的个数,e结尾变成偶数,o结尾变成单数
题意分析
明白了就是水题
代码总览
#include<stdio.h>
#include<string.h>
int main()
{
//freopen("in.txt","r",stdin);
int length,i,count;
char str[101] ;
while(scanf("%s",str) != EOF && str[0] != '#'){
count = 0;
length = strlen(str);
for(i = 0; i<length-1;i++){
if(str[i]=='1'){
count++;
}
}
if(count%2==0 && str[length-1] == 'e'){
str[length-1]='0';
}else if(count%2!=0 && str[length-1] == 'e'){
str[length-1]='1';
}else if(count%2==0 && str[length-1] == 'o'){
str[length-1]='1';
}else if(count%2!=0 && str[length-1] == 'o'){
str[length-1]='0';
}
for(i = 0; i<length;i++){
printf("%c",str[i]);
if(i == length-1){
printf("\n");
}
}
}
return 0;
//fclose(stdin);
}
谢谢您耐心的看完本文!
我是ACM小白,希望与诸君共勉!欢迎收听新浪微博:鹏威尔Will
HDU 2700的更多相关文章
- HDOJ/HDU 2700 Parity(奇偶判断~)
Problem Description A bit string has odd parity if the number of 1's is odd. A bit string has even p ...
- HDU 2700 Parity(字符串,奇偶性)
Parity Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- HDU 1043 八数码问题的多种解法
一.思路很简单,搜索.对于每一种状态,利用康托展开编码成一个整数.于是,状态就可以记忆了. 二.在搜索之前,可以先做个优化,对于逆序数为奇数的序列,一定无解. 三.搜索方法有很多. 1.最普通的:深搜 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- Selenium(Python)PageObject页面对象
使用PageObject页面对象的好处是, 当页面元素的位置发生改变时, 只需要去修改Xpath或者ID, 而不用去修改测试用例本身: 本次的思路是: 1.常用方法类 2.页面对象类 3.测试用例类 ...
- Python学习笔记(一)一一一环境安装错误总结
第三方库安装 1 windows存在多个版本的python,pip安装Python库失败 解决方案:进入对应官网下载安装包,步骤:1 下载安装包到C:\Python36\Lib\site-pack ...
- FU-A方式分包
当 NALU 的长度超过 MTU 时, 就必须对 NALU 单元进行分片封包. 也称为 Fragmentation Units (FUs). 0 1 2 3 0 1 2 3 4 5 6 7 8 9 ...
- Zookeeper与Eureka的区别
Zookeeper与Eureka的区别 想要了解Zk与eureka的区别首先要知道CAP定理 CAP定理 Mysql强一致性(数据唯一出处),设计数据库设计的三范式 (表必须有主键:表不能有重复的列: ...
- Codeforces-A. Shortest path of the king(简单bfs记录路径)
A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...
- 【radio-group、radio】 单选项组件说明
radio-group组件是包裹radio组件的容器 原型: <radio-group bindchange="[EventHandle]"> <radio .. ...
- 数据库Mysql的学习(二)-数据类型和创建
数据类型:数据列,存储过程参数,表达式和局部变量的数据特征. 整形: tinyint:一个字节,-128到127:2的7次方 smallint:两个字节,-32768到32767:2的15次方 med ...
- maven 教程二 深入
一:编写POM <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...
- hive创建外部表
Create [EXTERNAL] TABLE [IF NOT EXISTS] table_name [(col_name data_type [COMMENT col_comment], ...)] ...
- Thinkphp实现excel导出数据
前端: 点击导出触发click事件,传值export指令和args关键字(args是指我们是否有查询取哪些数据)到控制器 $(document).on("click", " ...