AF001-Editorial

PROBLEM

Angry Friends

PROBLEM LINK:

Author: Aman Nadaf
Tester: Aman Nadaf
Editorialist: Aman Nadaf

DIFFICULTY:

easy

PREREQUISITES:

sorting

PROBLEM:

Consider A number N with C digits. The number N is said to be Stronger if Reverse of that number is equal to the original number otherwise
it is considered Weaker. If the Number is Stronger Print C^C or if the Number is Weaker Print CXC.

EXPLANATION:

Read a String s, take a integer array of string length convert the string into integer array by subtracting each character with ‘/0’(null character) ie converting based on ASCII values in a for loop, sort the array using sort() function. then print each array element by type casting it to character using a for loop. OR u can directly use sort() function on the String itself.

Setter's Solution
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vll vector<long long int>

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	std::ios::sync_with_stdio(false);

	int t;
	cin >> t;
	while (t--)
	{
		string s;
		cin >> s;
		int arr[s.length()];
		for (int i = 0; i < s.length(); i++)
		{
			arr[i] = s[i] - '\0';
		}
		sort(arr, arr + s.length());
		for (int i = 0; i < s.length(); i++)
		{
			cout << (char)arr[i];
		}
		cout << endl;
	}
}

Feel free to share your approach here. Suggestions are always welcomed. :slight_smile: