Jishan's Log 9: Codeforces 399A solution

 Codeforces 399A: Helpful Maths

What does the problem want?

The problem states that a teacher has written a summation expression on the board and Xenia must solve it. However, Xenia can count in ascending order ONLY and not in any other way. We must arrange the numbers of the expression in ascending order so that Xenia can count them.

How to solve it?

The Algorithm:

1) Take a string input
2) Take a character array. Iterate through the string and insert the chars in the string into the char array if, and only if the char is not '+'. After that, sort the array and then finally print it.

The Code:

#include<bits/stdc++.h>
using namespace std;

#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


int main()
{

    fastio;
    string scin >> s;
    char temp[s.length()]; int n = 0;
    for(int i=0i<s.length(); ++i)
    {
        if(s[i] != '+')
        {
            temp[n= s[i];
            n++;
        }
    }
    sort(temptemp+n);
    for(int i=0i<n++i)
    {
        if(i == n-1cout << temp[i<< "\n"
        else cout << temp[i<< "+";
    }
}

Comments

Popular posts from this blog

Jishan's Log 14: Codeforces 69A solution

Jishan's Log 12: Codeforces 236A solution

Jishan's Log 13: Codeforces 96A solution