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

×

i can't find the error why wa??

include<iostream>

include<string>

using namespace std;

int main() { int t;

cin>>t;

string h;

getline(cin,h);

while(t--)
{
     string s1;
     string s2[4];
     int c=0;

    getline(cin,s1);
    for(int i=0;i<4;i++) cin>>s2[i];


    for(int i=0;i<4;i++)
    {
        if(s1.find(s2[i]) !=string::npos) c++;
    }

    if(c<2) cout<<"dissimilar\n";
    else cout<<"similar\n";

     getline(cin,h);


}

return 0;

}

asked 13 Jul '18, 15:51

sadi1500's gravatar image

0★sadi1500
1
accept rate: 0%


The error is because you are comparing parts of the string and not the whole word for example
tc#1
1
cook chef is good
coo ch no bad
will give you output similar but the result should be dissimilar
the reason for the output to be similar is s1.find(s2[i]) if true for coo as it finds "coo" in "cook" :/
So just take 2 string 1-D arrays of size 4 and compare each word if then c>2 print similar else dissimilar. I
hope this helps :)!!

link

answered 24 Jul '18, 19:02

joeyndchandler's gravatar image

4★joeyndchandler
624
accept rate: 0%

edited 24 Jul '18, 19:04

The error was that u didn't write '#' before including the the libraries .

Just add that and your code will work:)

link

answered 13 Jul '18, 21:51

krishyadav007's gravatar image

2★krishyadav007
1047
accept rate: 2%

actually he added '#' but since he just pasted it directly # is converted into heading due to markdown.

(13 Jul '18, 23:01) divik5444★

Can u tell he question

(24 Jul '18, 18:04) krishyadav0072★
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:

×33
×2

question asked: 13 Jul '18, 15:51

question was seen: 204 times

last updated: 24 Jul '18, 19:04