# Mirror World

Limits: 3s, 256 MB

Imagine a world inside mirror, where everything becomes reverse. Left hand becomes right hand, right hand becomes left hand. Mirror people read Arabic from left to write but they read English from right to left. In that world they have their own way of writing numbers as well. Fortunately, their numbers contain same digits (0,1,2,3,4,5,6,7,8 and 9) as our world, but they write it in a little bit different way than us. We write the digits of a number from left to right, but mirror people write it from right to left.

This is a companion discussion topic for the original entry at https://toph.co/p/mirror-world

Is it necessary to print 001 as 001?

Yes, print it as `001`.

pls give me some test case

but 423 is not smller than 395 in our world

``````int main ()
{
unsigned int M,N;
int i, T;
scanf("%d",&T);
for(i=1;i<=N;i++){
scanf("%u",&M);
scanf("%u",&N);
if(M<N){
printf("%u > %u",M,N);

}else if(M>N){
printf("%u < %u",M,N);

}else{
printf("%u = %u",M,N);
}

}
return 0;
}
``````

what is wrong in this code??
for mirror project.

``````#include <stdio.h>
#include <math.h>

int main()
{
int n, reversedNumber = 0, remainder;

printf("Enter an integer: ");
scanf("%d", &n);

while(n != 0)
{
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}

printf("Reversed Number = %d", reversedNumber);

unsigned int M,N;
int i, T;
scanf("%d",&T);
for(i=1;i<=N;i++){
scanf("%u",&M);
scanf("%u",&N);
if(M<N){
printf("%u > %u",M,N);

}else if(M>N){
printf("%u < %u",M,N);

}else{
printf("%u = %u",M,N);
}

}
return 0;
}
``````

what is the problem??

what is the orbolem in my code

``````#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int T,c=0;
long int m,n,p,q,r,s,k,l,a,b;
cin >> T;
for(c=1;c<=T;c++){
cin >> m >> n;
p=m/100;
r=m%10;
k=99*(p-r);
a=m-k;
q=n/100;
s=n%10;
l=99*(q-s);
b=n-l;
if(a==b){
cout <<setw(3)<<setfill('0')<<m <<" = "<<setw(3)<<setfill('0')<< n << endl;
}
else if(a>=b){
cout <<setw(3)<<setfill('0')<<m <<" > "<<setw(3)<<setfill('0')<< n << endl;
}
else if(a<=b) {
cout <<setw(3)<<setfill('0')<<m <<" < "<<setw(3)<<setfill('0')<< n << endl;
}
}
return 0;

}
``````

@EL_Drago Each number can have up to 500 digits. You can read such large numbers into `long long int`s.

423 is smaller number than 395 both in our world and mirror world.
what is it !!!

if i just reverse it and compare whats the problem?

ok if i reverse it and compare there is an invalid case like
10000000000 1 they are equal ,but it will show 10000000000<1
so we have to do extra work to handle these tai zeroes!

In the sample test case it is given that 423 = 423;
but reversed 423 is 324 which is less than 423 (in our world)

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
int a;
long long int b, c, d,g,h;
char e,f;
cin>>a;
for(b=0; b<a; b++)
{
cin>>e>>f;
g=stoi(e);
h=stoi(f);
strrev(e);
strrev(f);
c=stoi(e);
d=stoi(f);
if(c>d)
{
cout<<g<<" > "<<h<<endl;
}
else if(c<d)
{
cout<<g<<" < "<<h<<endl;
}
else if(c==d)
{
cout<<g<<" = "<<h<<endl;
}
}
}
``````

Actually strrev(str) is a C function defined in the header file string.h in C. You cannot include this in a C++ program. Yes, there are alternatives to this in C++, its called reverse which is defined under the header file algorithm(#include)

1 Like