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 ...
随机推荐
- [CodeForce455A]Boredom
题面描述 Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long ...
- 【WXS全局对象】consloe
consloe对象 方法: 原型:console.log( [String] ) 说明:用于在 console 窗口输出信息,一般用于程序调试使用示例: console.log支持arguments类 ...
- [2018 ACL Short and System] 对话系统
Short Paper(s) 1. Task-oriented Dialogue System for Automatic Diagnosis. (Cited by 0) Zhongyu Wei, ...
- asp.net mvc5 模式的现象思考
.net mv5简化了一些应用逻辑,与其说是mvc架构模式,不如说应用.net Entity更好. 现在你只需要去随便创建一个类 相关数据 然后用一个类去继承 DbContext 定义一个 DbSet ...
- Asp.net之数组应用
string[] abc=new string[8]{"1","2","3","4","1",&qu ...
- vmware安装64位系统“此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态”的问题
虚拟机使用的是VMware Workstation,并且首次在虚拟机体验64 位系统.在新建好虚拟机,运行时候就出现了VMware Workstation 的提醒:此主机支持 Intel VT-x,但 ...
- jquery datatable 常用例子
在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结. 一.DataTable简 ...
- wpa_supplicant与kernel交互
wpa_supplicant与kernel交互的操作,一般需要先明确驱动接口,以及用户态和kernel态的接口函数,以此来进行调用操作.这里分为4个步骤讨论. 1.首先需要明确指定的驱动接口.因为有较 ...
- python执行linux命令的两种方法
python执行linux命令有两种方法: 在此以Linux常用的ls命令为例: 方法一:使用os模块 1 2 3 shell# python >> import os >> ...
- 算法与数据结构实验题 6.3 search
★实验任务 可怜的 Bibi 刚刚回到家,就发现自己的手机丢了,现在他决定回头去搜索 自己的手机. 现在我们假设 Bibi 的家位于一棵二叉树的根部.在 Bibi 的心中,每个节点 都有一个权值 x, ...