HDU 2700 Parity(水~)

来源:互联网 发布:vb编程基础教程下载 编辑:程序博客网 时间:2024/05/21 06:30

Description
给你一个01数字串,最后一个字母为e或者o,你需要将e或o换成0或1,e使得整个串1的个数为偶数,o使得整个串1的个数为奇数
Input
多组输入,每组用例占一行,以#结束输入
Output
对于输入的每个字符串,输出将e/o转换成0/1后的串
Sample Input
101e
010010o
1e
000e
110100101o
#
Sample Output
1010
0100101
11
0000
1101001010
Solution
水题~
Code

#include<stdio.h>#include<string.h>int main(){    char c[33];    while(scanf("%s",c),c[0]!='#')    {        int len=strlen(c),res=0;        for(int i=0;i<len-1;i++)            if(c[i]=='1')                   res++;        if(c[len-1]=='e')            c[len-1]=res%2?'1':'0';        else            c[len-1]=res%2?'0':'1';        printf("%s\n",c);    }    return 0;}
0 0
原创粉丝点击