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

英文题~看懂题意就ok了。

e代表的是偶数奇偶性校验。

o代表的是奇数奇偶性校验。

0代表是。1代表否~

其实就是判断1的个数~

import java.util.Scanner;

/**
* @author 陈浩翔
*/
public class Main{ public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
while(sc.hasNext()){
String str = sc.next();
if(str.equals("#")){
return ;
}
int num=0;
for(int i=0;i<str.length()-1;i++){
if(str.charAt(i)=='1'){
num++;
}
}
if(num%2==0){//1出现的次数为偶数
if(str.charAt(str.length()-1)=='e'){//偶数奇偶校验
//0代表判断正确
System.out.println(str.substring(0, str.length()-1)+'0');
}else{
System.out.println(str.substring(0, str.length()-1)+'1');
}
}else{
if(str.charAt(str.length()-1)=='o'){//奇数奇偶校验
//0代表判断正确
System.out.println(str.substring(0, str.length()-1)+'0');
}else{
System.out.println(str.substring(0, str.length()-1)+'1');
}
}
}
}
}

HDOJ/HDU 2700 Parity(奇偶判断~)的更多相关文章

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

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

  2. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  3. HDOJ(HDU).1035 Robot Motion (DFS)

    HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...

  4. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  5. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

  6. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

  7. HDOJ(HDU).2266 How Many Equations Can You Find (DFS)

    HDOJ(HDU).2266 How Many Equations Can You Find (DFS) [从零开始DFS(9)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零 ...

  8. HDOJ(HDU).1258 Sum It Up (DFS)

    HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...

  9. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

随机推荐

  1. IIS应用地址池监控

    目的:公司服务器IIS有十几个应用地址池,总在不经意间停掉一个,停止线系统日志里会有一大堆警告日志,然后就停掉了,分析了好几次,网上有人说是某一个网站的问题应该查网站, 但是网站又有那么多地址,谁知道 ...

  2. 查看xcode的路径

    sudo /usr/libexec/locate.updatedb locate liblaunch_sim

  3. 0-C相关01:NSlog函数介绍。

      NSlog()函数介绍: 首先:NSlog()函数是cocoa的框架中提供的一个方法: 下图中最上方是它在Xcode中的路径: : 同样都是输出函数.下边我们来看一下,在O-C中NSlog()和在 ...

  4. C#动态二维数组输出

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  5. 冒泡排序--c#

    //冒泡排序 Console.WriteLine("请输入一个程序的数值"); int[] array = { 111, 2, 5, 32, 321 }; int temp = 0 ...

  6. ubuntu1404安装配置java环境(jdk8)

    这个安装比较简单,网上也有数不清的教学,我这里记录以下,方便以后万一失忆了回来看看能想起来.个人博客http://www.cnblogs.com/wdfwolf3/ 1.下载安装 言归正传,我们需要到 ...

  7. ACM HDU Primes(素数判断)

    Problem Description Writea program to read in a list of integers and determine whether or not eachnu ...

  8. Binary Tree Level Order Traversal 解题思路 ×

    要求: 树的层级遍历 思路: 1.两个队列,q1 q2 ,root放到q1 2.q1首元素出列,判断是否有左右孩子,有的话,放入q2.(循环此步骤值得q1为空) 3.q1 = q2,重复2,直到q1为 ...

  9. gooflow0.6的流程设计

    为何使用gooflow:1.兼容性好 2.扩展点很多可以个性化设计 3.配有api文档 4.json格式的数据传输 gooflow0.8版 由于最近项目需要,急需设计一个流程,考虑到时间问题,和用户个 ...

  10. 【算法】快速排序-Java版

    说在前面的话 平常码砖的时候,对于一个数组进行排序更多的是起泡排序,起泡排序对于一般不是很长的数组进行操作没什么问题,一旦数组过大,很明显效率低. 而快排是对起泡排序的一种改进,效率明显优高. 快排思 ...