A - Helpful Maths
Problem Link: [Codeforces 339A##link##]
- [tab]
- C++
#include<iostream> #include<algorithm> using namespace std; int main() { string s; char a[100]; cin >> s; int j = 0; for (int i = 0;i < s.length();i++) { if (s[i] != '+') { a[j] = s[i]; j++; } } sort(a, a + j); for (int i = 0;i < j;i++) { if (i == j - 1) cout << a[i] << endl; else cout << a[i] << "+"; } return 0; }
- Python3
s = input().split("+") s.sort() print("+".join(s))
- JAVA
import java.util.Arrays; import java.util.Scanner; public class PracticeCF { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.next(); s=s.replace("+", ""); char arr[]=s.toCharArray(); Arrays.sort(arr); for(int i=0;i<s.length();i++) { if(i==0) { System.out.print(arr[i]); } else { System.out.print("+"+arr[i]); } } } }