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

×

cakewalk

# PREREQUISITES

general programming skills

# PROBLEM

There are two arrays $a$ and $b$ each consisting of four strings. No two strings in each of the arrays are same. You have to tell whether the number of common strings in the arrays are more than or equal two or not.

This was an implementation problem. You iterate over the strings of one of the arrays (either $a$ or $b$, let us say $a$), and search whether the string is present in the other array (i.e. $b$) or not. Checking whether a string is a present in the array can be done by iterating over the elements of the array and comparing whether the element is equal to it or not. The below given pseudo code describes this.

common = 0;
for i = 1 to 4:
found = false;
// found denotes whether the string a[i] is present in the array b or not.
for j = 1 to 4:
if (a[i] == b[j]):
found = true;
if (found)
common += 1;


There were total 200 test cases. Number of operations taken in solving a test case will be around 4 * 4 * (time taken in comparing two strings). As the length of the strings could be at max 10. So total time in each test case will be $4 * 4 * 10 = 160$ operations. Overall time considering the test cases will be $160 * 200 = 3 * 10^5$ which will comfortably run in a second. You can assume that usually you can make around $10^8$ operations in a second. Please check following blog of Triveni for such details which would be quite useful for beginners.

## Some Implementation Related Details

In Java, there is an implementation related detail that you should take care. If you have two objects $s$, $t$ of String class, then you shouldn't check their equality by $s == t$ or not. This would be comparing the objects rather than comparing their content. You should use .equals() method, i.e. use s.equals(t). You can check this stack overflow link for more details about it.

Setter

# TESTER'S SOLUTION

This question is marked "community wiki".

asked 15 Apr '17, 22:10

2.5k52136170
accept rate: 20%

 3 Answer is hidden as author is suspended. Click here to view. answered 20 Apr '17, 21:24 (suspended) accept rate: 2%
 0 C++ STL Solution: We can use set of strings. Just insert all the 8 strings of both of the array and check it's size. if size <= 6, dishes are similar else they are dissimilar. My Accepted Solution: https://www.codechef.com/viewsolution/13216452 answered 17 Apr '17, 18:34 228●1●10 accept rate: 10%
 0 I solved this problem using set in C++. link answered 17 Apr '17, 22:43 3★dybbuk 47●3 accept rate: 20%
 0 Why didn't my solution work for Similar Dishes ? Without \n at the end of the input the program seemed to be running continuously. My solution : String contains method Can anyone explain what went wrong? answered 18 Apr '17, 10:20 1 accept rate: 0%
 0 This question is very easy . I solved this question by using set because set doesn't contains repeated values.. my solution: https://www.codechef.com/viewsolution/13216350 answered 20 Apr '17, 20:57 4★pk201996 11●1 accept rate: 0%
 0 My method does not seem to be accepted what is the most idiotic problem i have done in mine? Its almost similar to the setter's solution Source code in here N=int(input()) flag=0 for i in range(N): fdish=list(set(input().split())) map(str,fdish) sdish=list(set(input().split())) map(str,sdish) for i in range(len(fdish)): for j in range(len(sdish)): if fdish[i] in sdish: flag+=1 break if flag>=2: print("Similar") else: print("Dissimilar")  answered 28 Apr '17, 13:37 1 accept rate: 0%
 0 t=int(input()) for i in range(0,t): s=0 a=list(input().split()) b=list(input().split()) for i in range(0,4): for j in range(0,4): if a[i]==b[j]: s+=1 if s>=2: print("similar") else: print("dissimilar") answered 29 Jan '18, 08:58 1 accept rate: 0%

# include<string.h>

int main() { int t,i,j,count; scanf("%d",&t); char s1[4][11],s2[4][11]; while(t--) { for(i=0;i<4;i++) scanf("%s",s1[i]); for(i=0;i<4;i++) scanf("%s",s2[i]); count=0; for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(strcmp(s2[j],s1[i])==0) { count++; } } } if(count>=2) printf("similar\n"); else printf("dissimilar\n"); } return 0; }

answered 01 Feb '18, 09:05

1
accept rate: 0%

# include<string.h>

int main() { int t,i,j,count; scanf("%d",&t); char s1[4][11],s2[4][11]; while(t--) { for(i=0;i<4;i++) scanf("%s",s1[i]); for(i=0;i<4;i++) scanf("%s",s2[i]); count=0; for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(strcmp(s2[j],s1[i])==0) { count++; } } } if(count>=2) printf("similar\n"); else printf("dissimilar\n"); } return 0; }

answered 01 Feb '18, 09:47

1
accept rate: 0%

 0 why do we have 2d array in this problem????? answered 05 Dec '18, 01:03 1 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

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

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×15,477
×122
×7

question asked: 15 Apr '17, 22:10

question was seen: 1,779 times

last updated: 05 Dec '18, 01:03