You are not logged in. Please login at www.codechef.com to post your questions!

×

A very interesting question needs help !!

Question link : https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/two-strings-4/

NOTE: my input : 2 sumut sumu sumit sumit gives output NO NO but it shud give NO YES . //i have problem in this.

MY CODE::

include<iostream>

include<string>

using namespace std;

int main()

{

int t;

cin>>t;

string s1[t],s2[t];

long int a[26]={0},l[t]={0};

for(int i=0;i<t;i++)

{

cin>>s1[i]>>s2[i];

}

for(int k=0;k<t;k++)

{

for(char i='a';i<'z';i++)

{

for(int j=0;j<s1[k].size();j++)

{

if(s1[k].at(j)==i){a[i-97]++;}

}

for(int j=0;j<s2[k].size();j++)

{

if(s2[k].at(j)==i){a[i-97]--;}

}

}

for(int i=0;i<26;i++)

{

if(a[i]==0){l[k]++;}

}

}

for(int k=0;k<t;k++)

{

if(l[k]==26){cout<<endl<<"YES";}

else{cout<<endl<<"NO";}

}

return 0;

}

asked 09 Dec '18, 18:17

chaitu12789's gravatar image

0★chaitu12789
122
accept rate: 0%

edited 09 Dec '18, 18:19


You Haven't initialized the a[] to 0 for the remaining test cases.

Initially it's 0, and hence you are getting correct output for test case 1. (Your Output is YES for the input:1 sumit sumit)

Just make all 26 values 0 in every test case.

Also, change your i<'z' to i<='z'.

link

answered 09 Dec '18, 19:00

black_truce's gravatar image

4★black_truce
1697
accept rate: 26%

Thanks, I got it :)

(10 Dec '18, 13:15) chaitu127890★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×643

question asked: 09 Dec '18, 18:17

question was seen: 166 times

last updated: 10 Dec '18, 13:15