PROBLEM
Stronger or Weaker
PROBLEM LINK:
Author: Aman Nadaf
Tester: Aman Nadaf
Editorialist: Aman Nadaf
DIFFICULTY:
cakewalk
PREREQUISITES:
None.
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 the value of N. then store the value of N in other variable og ,take a loop until N is equal to 0
reverse the number by taking mod of N with 10 then adding to a number multiplied by 10 ,for every iteration divide N by 10 and store in N and increment the count variable c. compare the reversed number with original number og ,if they are same print c^c else print cxc.
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);
ll t;
cin >> t;
while (t--)
{
ll n,og,c=0;
cin>>n;
og=n;
ll rev=0,sum=0;
while(n!=0)
{
rev=rev*10+n%10;
n=n/10;
c++;
}
if(rev==og)
{
cout<<pow(c,c)<<endl;
}
else
{
cout<<c*c<<endl;
}
}
}
Feel free to share your approach here. Suggestions are always welcomed.