Hi friends, I am going to post the solve of the problem '226A - Stones on the Table' of Codeforces.
The problem screenshots is given below:
Code:
This is only for the solutions & algorithm of the problems of Codeforces. We highly recommend you to try hard yourself at first, then if you fail, you can only check the logic from our code.Don't Copy-Paste our code exactly.If you do this,your logic will not be improved/developed. So, try to realize the logic. Stay with us
BidMag
Tuesday, August 7, 2018
Codeforces Problems' Solution (339A - Helpful Maths)
#include <stdio.h>
#include <string.h>
int main ()
{
char s[1000];
int i, j = 0, k, l, ln, arr[1000], m, n, temp;
scanf("%s", s);
ln = strlen(s);
for(i = 0; i < ln; i++)
{
if((i % 2) == 0)
{
arr[j] = (int) s[i];
j++;
}
}
for(m = 1; m < j; m++)
{
for(n = 0; n < (j - m); n++)
{
if(arr[n] > arr[n + 1])
{
temp = arr[n];
arr[n] = arr[n + 1];
arr[n + 1] = temp;
}
}
}
for(k = 0; k < j; k++)
{
if(k == (j - 1))
{
printf("%c", (char) arr[k]);
}
else
{
printf("%c%c", (char) arr[k], '+');
}
}
printf("\n");
return 0;
}
Subscribe to:
Posts (Atom)