๐Day 13 โ Teacherโs Day Challenge | Helpful Maths


๐๏ธ Date: August 06, 2025
๐งฉ Platform: Codeforces
๐ข Problems Solved Today: 1
๐ฏ Focus Topic: Strings, Sorting
๐ Table of Contents
Daily Summary
๐งฉ 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
Metric | Value |
Problems Solved | 1 |
Topics Covered | String Manipulation, Sorting |
Tools Used | C++ |
Next Focus | Continue with Basic String/Sorting Problems |
Day | 13 / 43 |
๐ท๏ธ Tags:#codeforces #string #sorting #beginner #cpp #dsa #43DaysChallenge
Subscribe to my newsletter
Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
