๐Ÿ“˜Day 13 โ€“ Teacherโ€™s Day Challenge | Helpful Maths

TanishiTanishi
2 min read

๐Ÿ—“๏ธ Date: August 06, 2025
๐Ÿงฉ Platform: Codeforces
๐Ÿ”ข Problems Solved Today: 1
๐ŸŽฏ Focus Topic: Strings, Sorting


๐Ÿ”— Table of Contents


๐Ÿงฉ Problem 1 โ€“ Helpful Maths

๐Ÿ“š Difficulty: Easy
๐Ÿง  Concepts: String Manipulation, Sorting


๐Ÿ“„ Problem Statement (Summary):
Xenia, a beginner at math, wants to calculate a sum but only if the numbers are in non-decreasing order.
You are given a string containing only digits 1, 2, 3 and '+' signs (e.g., "3+2+1"). Rearrange it so that the numbers appear in increasing order (e.g., "1+2+3"), and print the new string.


๐Ÿ”ข Input Format:
A single string s containing digits 1, 2, 3 and '+'.

๐Ÿงพ Output Format:
Print the reordered sum where digits appear in non-decreasing order, separated by '+'.

๐Ÿ” Example 1:
Input:
3+2+1
Output:
1+2+3


๐Ÿ” Example 2:
Input:
1+1+3+1+3
Output:
1+1+1+3+3


๐Ÿ’ก Approach:

  • Read the input string.

  • Extract only the digits (1, 2, 3) from it.

  • Sort the digits.

  • Reconstruct the output string by joining digits with '+'.


๐Ÿงช Code (C++):

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    string s, str;
    cin >> s;

    // Extract only digits from the input
    for (char c : s) {
        if (c == '1' || c == '2' || c == '3') {
            str += c;
        }
    }

    // Sort the extracted digits
    sort(str.begin(), str.end());

    // Output in required format
    for (int i = 0; i < str.length() - 1; i++) {
        cout << str[i] << "+";
    }
    cout << str[str.length() - 1];

    return 0;
}

๐Ÿ“ธ Submission Screenshot:


โœ… Key Takeaways:

  • Convert the input into useful data by filtering characters.

  • Sort the result to follow non-decreasing order.

  • Reconstruct formatted output using loops and conditionals.


๐Ÿ“ˆ Daily Summary

MetricValue
Problems Solved1
Topics CoveredString Manipulation, Sorting
Tools UsedC++
Next FocusContinue with Basic String/Sorting Problems
Day13 / 43

๐Ÿท๏ธ Tags:
#codeforces #string #sorting #beginner #cpp #dsa #43DaysChallenge

0
Subscribe to my newsletter

Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tanishi
Tanishi