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