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. MVC下的Area区域知识点

    新建area区域 1.如果与根目录下的url相同,那么需要在RouteConfig.cs中 public static void RegisterRoutes(RouteCollection rout ...

  2. NGUI制作流光效果

    效果展示: 技巧: 1.勾选UIPanel下的Normal启用UI的法线贴图,并建立带有法线贴图的UI对象(此处用NGUI自带的Reflector.Atlas中的图作为UI). 2.建立点光源并为其添 ...

  3. Java开发工程师(Web方向) - 03.数据库开发 - 期末考试

    期末考试 编程题 本编程题包含4个小题,覆盖知识点从基础的JDBC.连接池到MyBatis. 1(10分) 有一款在线教育产品“天天向上”主要实现了在手机上查看课程表的功能.该产品的后端系统有一张保存 ...

  4. Java开发工程师(Web方向) - 02.Servlet技术 - 第3章.Servlet应用

    第3章.Servlet应用 转发与重定向 转发:浏览器发送资源请求到ServletA后,ServletA传递请求给ServletB,ServletB生成响应后返回给浏览器. 请求转发:forward: ...

  5. C 计算时间差

    #include <stdio.h>int main(){ //新建四个变量 la 代表小时 kc代表时间 int l,k,a,c; //输入 两个时间 scanf("%d %d ...

  6. Python全栈 正则表达式(re模块正则接口全方位详解)

    re模块是Python的标准库模块 模块正则接口的整体模式 re.compile 返回regetx对象 finditer fullmatch match search 返回 match对象 match ...

  7. 机器学习介绍(introduction)-读书笔记-

    一,什么是机器学习 第一个机器学习的定义来自于 Arthur Samuel.他定义机器学习为,在进行特定编程的情况下,给予计算机学习能力的领域.Samuel 的定义可以回溯到 50 年代,他编写了一个 ...

  8. 【转】跨平台移动端开发框架NativeScript 发布正式版本

    原文:http://news.cnblogs.com/n/520865/ Nativescript 项目地址:http://www.telerik.com/nativescript “一次编码,处处运 ...

  9. C复合文字

    C99之前,可以传递数组,但是没有所谓的数组常量可供传递,于是新增了复合文字. 普通数组声明方法: int d[2]={10,20}; 复合文字声明: 与数组名相同,常量同时代表元素的地址. (int ...

  10. 【Machine Learning】如何处理机器学习中的非均衡数据集?

    在机器学习中,我们常常会遇到不均衡的数据集.比如癌症数据集中,癌症样本的数量可能远少于非癌症样本的数量:在银行的信用数据集中,按期还款的客户数量可能远大于违约客户的样本数量.   比如非常有名的德国信 ...