http://acm.hdu.edu.cn/showproblem.php?pid=2700

题目意思很重要;  //e:是要使字符串中1的个数变成偶数。o:是要使字符串中1的个数变成奇数

Parity

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1855    Accepted Submission(s): 1447

Problem Description
A bit string has odd parity if the number of 1's is odd. A bit string has even parity if the number of 1's is even.Zero is considered to be an even number, so a bit string with 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 consists of one or more strings, each on a line by itself, followed by a line containing only "#" that signals the end of the input. Each string contains 1–31 bits followed by either a lowercase letter 'e' or a lowercase letter 'o'.
 
Output
Each line of output must look just like the corresponding line of input, except that the letter at the end is replaced by the correct bit so that the entire bit string has 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
 
Source
 
Recommend
zty
 //e:是要使字符串中1的个数变成偶数。o:是要使字符串中1的个数变成奇数。
#include<stdio.h>
#include<string.h>
int main()
{
int i,l,r;
char str[];
while(~scanf("%s",str)&&str[]!='#')
{
r=;
l=strlen(str);
for(i=;str[i]!=;i++)
{
if(str[i]=='')
r++;
}
for(i=;i<l-;i++)
printf("%c",str[i]);
if(str[l-]=='e')
{
if(r%==)
printf("");
else
printf("");
}
if(str[l-]=='o')
if(r%!=)
printf("");
else
printf("");
printf("\n");
}
return ;
}

HDU-2700 Parity的更多相关文章

  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 2700

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

  4. HDU——PKU题目分类

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

  5. 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733

    1.POJ 1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5744   Accepted: ...

  6. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  7. [转] HDU 题目分类

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

  8. HDU ACM 题目分类

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

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

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

随机推荐

  1. frame 第三节

    1.准备3个文件 main.html: <html> <head> <title>框架</title> </head> <frames ...

  2. dp方程

    1.        资源问题1 -----机器分配问题 F[I,j]:=max(f[i-1,k]+w[i,j-k]) 2.        资源问题2 ------01背包问题   F[I,j]:=ma ...

  3. 【BZOJ2793】【数学】[Poi2012]Vouchers

    Description 考虑正整数集合,现在有n组人依次来取数,假设第i组来了x人,他们每个取的数一定是x的倍数,并且是还剩下的最小的x个. 正整数中有m个数被标成了幸运数,问有哪些人取到了幸运数. ...

  4. Linux运维工程师面试

    一.Linux操作系统知识 1.常见的Linux发行版本都有什么?你最擅长哪一个?它的官网网站是什么?说明你擅长哪一块?   2.Linux开机启动流程详细步骤是什么?系统安装完,忘记密码如何破解? ...

  5. Java并发编程二三事

    Java并发编程二三事 转自我的Github 近日重新翻了一下<Java Concurrency in Practice>故以此文记之. 我觉得Java的并发可以从下面三个点去理解: * ...

  6. Shell数组

    #!/bin/bash#数组的使用#数组赋值方式:#1. user[index]=value index为0,1,2,3,4....数组下标值#2. user=(value0 value1 value ...

  7. web 中 bbs 例子(多次递归)

    数据库设计:create table `header`(  // 父表  parent int not null, //父级  poster varchar(20) not null, //作者  p ...

  8. node 无解回调 有解了

    http://cssor.com/javascript-workflow-by-tofishes.html

  9. jquery直接获取html页面元素

    大家都会用$('div')来获取div并对其进行一些操作,今天用到一个函数发现$('div')与getElementBy系列函数得到的对象并不一样. 然后去查了下,发现$('div')得到的是一个数组 ...

  10. JAVA NIO之Character Set

    明白以下几个概念: 字母集(Character Set),汉字,特殊符号,字母这些都是字符集: 字符编码集(Coded character set),将字符集的字符使用数字进行编码:比如ASCII,就 ...