Skip to content

Commit 7957f54

Browse files
authored
Create 35_hacker_two_strings.cpp
1 parent e2cf802 commit 7957f54

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

35_hacker_two_strings.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// main.cpp
3+
// Lecture 34
4+
//
5+
// Created by Prince Kumar on 17/04/19.
6+
// Copyright © 2019 Prince Kumar. All rights reserved.
7+
//
8+
// HACKER EARTH
9+
10+
// --- ** Problems on Two Strings ** --- //
11+
12+
13+
#include <iostream>
14+
using namespace std;
15+
int main()
16+
{
17+
int T; cin>>T;
18+
while(T--)
19+
{
20+
string s1,s2; cin>>s1>>s2;
21+
// declare array for s1 and s2;
22+
23+
// for s1
24+
int a[26]={0};
25+
26+
// for s2
27+
int b[26]={0};
28+
29+
// length of string
30+
int k = (int)s1.size();
31+
32+
for(int i=0;i<k;i++)
33+
{
34+
int x = s1[i]-97; // In c++ automatic data type conversion in char to int
35+
a[x]++;
36+
37+
int y = s2[i]-97;
38+
b[y]++;
39+
}
40+
41+
42+
// we declare count
43+
int count=0;
44+
45+
// we got completer array a and b
46+
47+
for(int j=0;j<26;j++)
48+
{
49+
if(a[j]!=b[j])
50+
count++;
51+
}
52+
if(count==0)
53+
cout<<"YES"<<endl;
54+
else
55+
cout<<"NO"<<endl;
56+
}
57+
}
58+
59+

0 commit comments

Comments
 (0)