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