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. Allure--自动化测试报告生成

    之前尝试使用过testNG自带的测试报告.优化过reportNG的测试报告,对这两个报告都不能满意.后经查找资料,发现有个神器: Allure(已经有allure2了,笔者使用的就是allure2), ...

  2. git基础(1)

    一.获取git仓库(两种方法)1.现有目录初始化 git init目录有文件(非空文件)进行跟踪执行:git add+文件名提交:git commit -m(提交信息说明) 2.克隆现有代码仓库的代码 ...

  3. selenium,unittest——参数化url,并多线程加快脚本运行速度

    利用参数化连续打开网页: #encoding=utf-8import unittestimport paramunittestimport timefrom selenium import webdr ...

  4. Lua学习笔记(1): HelloWorld和数据类型

    Lua是一个轻量级的脚本语言,由c语言编写,容易嵌入到应用中,深受游戏开发者的青睐 环境安装 选用SciTE作为lua的IDE 可以在github找到这个开源的软件 SciTE下载链接 安装好之后打开 ...

  5. leetcode-反转链表

      转载至:https://blog.csdn.net/fx677588/article/details/72357389 反转一个单链表.   示例: 输入: 1->2->3->4 ...

  6. 洪水!(Flooded! ACM/ICPC World Final 1999,UVa815)

    题目描述:竞赛入门经典的习题4-10 解题思路:1.把各个网格想象成一个数组 2.排序 3.雨水总体积去铺满 //太懒了只写了求海拔 #include <stdio.h> #define ...

  7. default & delete

    一.使用“=default” 1. 显式生成拷贝控制成员的合成版本 class A { public: A() = default; A(const A &) = default; A& ...

  8. 数据库索引(结合B-树和B+树)

    数据库索引,是数据库管理系统中一个排序的数据结构以协助快速查询.更新数据库表中数据.索引的实现通常使用B树及其变种B+树. 在数据之外,数据库系统还维护着满足特定查找算法的数据结构,这些数据结构以某种 ...

  9. 分页查询es时,返回的数据不是自己所期望的问题

    在进行es分页查询时,一般都是用sql语句转成es查询字符串,在项目中遇到过不少次返回的数据不是自己所期望的那样时,多半原因是自己的sql拼接的有问题. 解决办法:务必要保证自己的sql语句拼接正确.

  10. iOS-明杰解决字段冲突,及数组映射

    /** 替换关键字的属性名 */ + (NSDictionary *)mj_replacedKeyFromPropertyName{ return @{@"UUID":@" ...