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的更多相关文章

  1. 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 ...

  2. HDU 2700 Parity(字符串,奇偶性)

    Parity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  3. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  4. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  5. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  6. HDU 1043 八数码问题的多种解法

    一.思路很简单,搜索.对于每一种状态,利用康托展开编码成一个整数.于是,状态就可以记忆了. 二.在搜索之前,可以先做个优化,对于逆序数为奇数的序列,一定无解. 三.搜索方法有很多. 1.最普通的:深搜 ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. hdu1730Northcott Game(nim博弈)

    Northcott Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. springboot在application.yml中使用了context-path属性导致静态资源法加载,如不能引入vue.js,jquery.js,css等等

    在springBoot配置中加入上下文路径 server.context-path=/csdn js,img等静态文件无法加载,出现404的问题 <script type="text/ ...

  3. 【swiper】 滑块组件说明

    swiper 滑块视图容器,其原型如下: <swiper indicator-dots="[Boolean]" indicator-color="[Color]&q ...

  4. Java学习 · 初识 多线程

    多线程 1. 基础概念 a)     程序 Program i.           静态代码,指令集,应用程序执行的蓝本 b)    进程 Process i.           动态概念,正在运 ...

  5. HTML/JSP中一些单书名号标签的用途<%-- --%><!-- --><%@ %><%! %><% %><%= %>

    注释 <%-- --%>是(JSP)隐式注释,不会在页面显示的注释 <!-- -->是(Html)显示注释,会在JSP页面显示 关于注释还有单行隐式注释//和多行隐式注释/* ...

  6. 硬件PCB Layout布局布线Checklist检查表(通用版)

    按部位分类 技术规范内容 1 PCB布线与布局 PCB布线与布局隔离准则:强弱电流隔离.大小电压隔离,高低频率隔离.输入输出隔离.数字模拟隔离.输入输出隔离,分界标准为相差一个数量级.隔离方法包括:空 ...

  7. 软工实践-Alpha 冲刺 (1/10)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 学习了UI设计软件的使用,了解了项目开发的具体流程. 展示 ...

  8. Sparsity Invariant CNNs

    文章链接 Abstract 本文研究稀疏输入下的卷积神经网络,并将其应用于稀疏的激光扫描数据的深度信息完成实验.首先,我们表明,即使当丢失数据的位置提供给网络时,传统卷积网络在应用于稀疏数据时性能也很 ...

  9. 用 C# 实现文件信息统计(wc)命令行程序

    软件的需求分析 程序处理用户需求的模式为: wc.exe [parameter][filename] 在[parameter]中,用户通过输入参数与程序交互,需实现的功能如下: 1.基本功能 支持 - ...

  10. Unity3d学习日记(一)

      闲来无事开始自学unity3d,发现还挺容易入门的,添加资源文件以及用c#编写脚本都很方便.   前面在Unity官方教程上自学了一段时间,跟着教程写了个space_shooter的小游戏,虽然游 ...