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