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 ;
}

最新文章

  1. MDK st-link下载STM32程序出现Internal command error和Error:Flash download failed. Target DLL
  2. div 添加滚动条
  3. 百度eCharts体验
  4. java19
  5. linux打包与压缩
  6. ListView 刷新加载控件
  7. JQuery_处理元素和浏览器的窗口的尺寸
  8. Objective-C学习笔记_命令行参数获取
  9. CSS设置行内元素和块级元素的水平居中、垂直居中
  10. csdn 刷分小工具(刷了1000多被封了,慎用)
  11. 细谈Java
  12. hough变换是如何检测出直线和圆的?
  13. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解
  14. 使用github pages搭建个人博客
  15. 前端面试知识点集锦(JavaScript篇)
  16. 浏览器仿EXCEL表格插件 - 智表ZCELL产品V1.4发布
  17. 关于浏览器兼容问题——还有移动端meta问题
  18. adb 查看包名或其他
  19. ef中文文档
  20. zookeeper 图形化的客户端工具:ZooInspector

热门文章

  1. UIView的frame和bounds区别
  2. Solr集群的搭建以及使用(内涵zookeeper集群的搭建指南)
  3. SQL的定义与使用
  4. IniParse解析类
  5. 认识linux权限
  6. android studio 自动序列化类插件
  7. 使用Chrome DevTools的Timeline分析页面性能
  8. mysql中char与varchar的区别
  9. 使用WMI监控进程启动与结束
  10. C# 判断中文字符(字符串)