Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Strings problem solution

YASH PAL, 31 July 2024
In this HackerEarth Strings problem solution, Anton and Artur are old friends. Today they practice in writing strings. Anton must write each string with the lengths exactly N , based on the alphabet of size M . And Arthur, on the contrary, should write each string with the lengths exactly M, based on the alphabet of size N . Guys spend 1 second to write a single string. They start writing at the same time.
And now boys are interested in one question. Is it true, that they will finish together? (It is assumed that the guys don’t pause during the writing of strings).
HackerEarth Strings problem solution

HackerEarth Strings problem solution.

#include <bits/stdc++.h>

using namespace std;

string solve()
{
string a, b;
cin >> a >> b;
if (a == b)
return "YES";
if (a.size() != 1 || b.size() != 1)
return "NO";
if (a > b)
swap(a, b);
return (a[0] == '2' && b[0] == '4') ? "YES" : "NO";
}

int main()
{
int test = 0;
cin >> test;
while (test--)
{
cout << solve();
if (test)
cout << endl;
}
}

Second solution

#include<bits/stdc++.h>

using namespace std;

#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it,v) for( __typeof((v).begin())it = (v).begin() ; it != (v).end() ; it++ )
#define ll long long
#define llu unsigned long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(x) x.begin(),x.end()
#define mset(x,v) memset(x, v, sizeof(x))
#define sz(x) (int)x.size()

int main()
{
int t;
scanf("%d",&t);
assert(1 <= t && t <= 50);
while(t--)
{
string n,m;
cin>>n>>m;
assert(1 <= sz(n) && sz(n) <= 10000);
assert(1 <= sz(m) && sz(m) <= 10000);
if((n == m) || (n == "2" && m == "4") || (n == "4" && m == "2"))
{
printf("YESn");
}
else
{
printf("NOn");
}
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes