描述

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.

输入

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

输出

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’).

样例输入

101e
010010o
1e
000e
110100101o

样例输出

1010
0100101
11
0000
1101001010

题目来源

Mid-Central USA 2008

分析:
不算难的模拟,根据奇偶性来修改字符串。
代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{string s;int t;while(cin>>s){t=0;if (s[0]=='#') break;int l=s.length();for (int i=0;i<l;i++){if (s[i]=='1') t++;//统计1的个数来判断奇偶}if (t%2==0)//偶数{if (s[l-1]=='e')s[l-1]='0';if (s[l-1]=='o')s[l-1]='1';}else{if (s[l-1]=='e')s[l-1]='1';elseif (s[l-1]=='o')s[l-1]='0';}cout<<s<<endl;}return 0;
}

【模拟】Parity相关推荐

  1. 【巧妙算法系列】【Uva 11464】 - Even Parity 偶数矩阵

    偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...

  2. Modebus Slave 与 Modbus Poll主从设备模拟软件与Configure Virtual Serial串口模拟软件使用

    场景 Configure Virtual Serial Port Driver 1.多个虚拟串口映射: 2.收/发多线程架构发多线程架构: 3.支持虚拟串口参数同步指令支持虚拟串口参数同步指令: 4. ...

  3. 【CodeForces - 298C】Parity Game (思维,有坑)

    题干: You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar be ...

  4. 利用Teensy进行EM410x卡模拟以及暴力破解EM410X类门禁系统可行性猜想

    前些天Open入手了Teensy++2.0模拟EM410X,并且针对EM410X的门禁进行了一次暴力破解测试,以下就是相关代码以及内容. 什么是低频?什么是EM410x? 首先,我不得不再次提一下那些 ...

  5. 模拟NAND FLASH 读写BCH ECC校验

    一.模拟NAND FLASH 读写BCH ECC校验 将内核源码里的bch校验程序分离出来,从而可以手动修改原始数据和bch校验码,达到模拟出错纠正过程. 源码 bch.c.bch.h.types.h ...

  6. LIN总线解析与UART模拟LIN从机实战

    文章目录 目录 文章目录 前言 一.LIN总线是什么? 1.LIN总线的标准 2.LIN总线形式 3.帧的构成 二.UART模拟LIN从机的实现 1.方案概述 2.串口中断处理 3.同步间隔断中断处理 ...

  7. even parity

    转自http://www.acmerblog.com/uva-11464-even-parity-4653.html 这道题的算法实现态变态了,奇妙的技巧,至少我是这样认为的.我想了很久也不会,书上代 ...

  8. DLT645-2007模拟表 python源码

    DLT645-2007模拟表 python源码 # -*- coding: utf-8 -*- import sys import time import binascii import serial ...

  9. linux cisco路由器,Linux认证:Linux用dynamic模拟cisco路由器

    环境 : centos5.2 软件: dynamic.cisco-ios 1: 下载dynamic bin文件 . wget http://www.ipflow.utc.fr/dynamips/dyn ...

  10. STM32模拟I2C协议获取MLX90615红外温度传感器测温数据(Open Drain管脚配置)

    STM32模拟I2C协议获取MLX90615红外温度传感器测温数据(Open Drain管脚配置) STM32的GPIO管脚可以配置为Open Drain输出模式,并且有两个功能: 可以设置内部上拉, ...

最新文章

  1. mysql 5.7 xbackup_CentOS 7 下 MySQL 5.7 配置 Percona Xtrabackup
  2. Objects非空判断_requireNonNull方法
  3. java跨平台的特性_【简答题】什么是跨平台特性?Java怎样实现跨平台特性?
  4. 怎样在hdfs上创建多级目录文件夹_【HDFS API编程】第一个应用程序的开发-创建文件夹...
  5. LG 源代码或被盗,如何才能毫发无损地要回来?
  6. Abp vNext 自定义 Ef Core 仓储引发异常
  7. 秒杀/抢购系统设计优化
  8. oracle vm virtualbox无网络连接_VirtualBox 安装 Windows 2000/XP 测试
  9. html5手机页面设计软件,5个非常优秀的免费H5页面制作工具(推荐)
  10. 即时聊天软件开发体会
  11. HTML制作菜鸟教程网站首页
  12. linux c语言怎么把2个字符串拼起来,【C语言学习笔记】字符串拼接的3种方法 .
  13. 相亲也内卷?被程序员的相亲规划整不会了......
  14. 数据库实体之间的关联关系:一对一、一对多、多对多
  15. 第一站 Theano 简介
  16. linux 兼职,远程后端(兼职)
  17. 2015年11月小结
  18. 知识图谱基础入门(一)
  19. el-cascader省市区 三级数据
  20. HD Tune结合硬盘再生器HDDREG快速修复硬盘错误

热门文章

  1. JetBrain注册学生免费帐号方法
  2. 验证性因子分析(二)
  3. 如何设置计算机桌面待办事项,Windows电脑桌面云便签怎么设置每天提醒待办事项?...
  4. 【继电器模块的电路设计和分析】
  5. 机器学习二(python sklearn逻辑回归)
  6. 联想服务器怎么拆硬盘,联想ThinkStation P900工作站高清拆解
  7. SQL Server设置SQL Server身份验证
  8. 九:什么是热部署,为什么要用这个?
  9. mmgrid cols表头列隐藏
  10. 排除AP无法上线原因