Solution:
#include<iostream>
using namespace std;
int main()
{
int n,p;
cin>>n>>p;
if(n>p)
{
while(n%10!=0)
{
n++;
p--;
}
cout<<n<<" "<<p;
}
else if(p>n)
{
while(p%10!=0)
{
p++;
n--;
}
cout<<n<<" "<<p;
}
}
Solution:
#include<iostream>
using namespace std;
int main()
{
int n,p;
cin>>n>>p;
if(n>p)
{
while(n%10!=0)
{
n++;
p--;
}
cout<<n<<" "<<p;
}
else if(p>n)
{
while(p%10!=0)
{
p++;
n--;
}
cout<<n<<" "<<p;
}
}
The algorithm will first have to reverse the string and check with the second string. We can do this both in library function and also by using a loop.
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
string s,t;
cin>>s>>t;
string rev1="";
//reverse(s.begin(),s.end()); //Library function
//using loop
for (int i = s.size() - 1; i >= 0; i--)
{
rev1 = rev1 + s[i];
}
if(rev1==t)
cout<<"YES";
else
cout<<"NO";
}