水题 Parity

发布时间:2016-12-9 17:53:31 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"水题 Parity",主要涉及到水题 Parity方面的内容,对于水题 Parity感兴趣的同学可以参考一下。

Parity Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 11   Accepted Submission(s) : 10 Font: Times New Roman | Verdana | Georgia Font Size: ← → 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 主要是理解题意,理解啦很好做的 #include<stdio.h> #include<string.h> int main() { char str[35]; int n,i,c; while(scanf("%s",str)!=EOF) { if(str[0]=='#') break; n=strlen(str); c=0; for(i=0;i<n;i++) { if(str[i]=='1') c++; } if(c%2==0&&str[n-1]=='e') {  str[n-1]='0';     printf("%s\n",str); } if(c%2==0&&str[n-1]=='o') { str[n-1]='1'; printf("%s\n",str); } if(c%2==1&&str[n-1]=='e') {  str[n-1]='1';     printf("%s\n",str); } if(c%2==1&&str[n-1]=='o') {  str[n-1]='0';     printf("%s\n",str); } } return 0; }

上一篇:寒冰王座
下一篇:极大或极小的数字

相关文章

关键词: 水题&nbsp;Parity

相关评论