Code Parsing CodeForces - 255B

http://codeforces.com/problemset/problem/255/B

Note
In the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won’t change.

In the second test the transformation will be like this:

string “yxyxy” transforms into string “xyyxy”;
string “xyyxy” transforms into string “xyxyy”;
string “xyxyy” transforms into string “xxyyy”;
string “xxyyy” transforms into string “xyy”;
string “xyy” transforms into string “y”.
As a result, we’ve got string “y”.

In the third test case only one transformation will take place: string “xxxxxy” transforms into string “xxxx”. Thus, the answer will be string “xxxx”.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    int i,j,n,flag,flagm,k;
    char ch[1000001];
    while (gets(ch))
    {
        flag = 0;
        flagm = 0;
        n = strlen(ch);
        for (i = 0; i < n; i++)
        {
            if(ch[i] == 'x') flag++;
            else flagm++;
        }
        if(flag > flagm)
        {
            k = flag - flagm;
            for(j = 0; j < k; j++)
                printf("x");
        }
        else if(flagm > flag)
        {
            k = flagm - flag;
            for(j = 0; j < k; j++)
            {
                printf("y");
            }
        }
        else continue;
        printf("\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值