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

×

EASY

# EXPLANATION

This was the easiest problem of the contest. All one had to was to move over all characters is S and check if they were present in J as well. Checking could be done either by iterating over all character of J which takes time O(|J|) or by keeping an array/hashset for O(1) look up.

# SETTER'S SOLUTION

Can be found here.

# TESTER'S SOLUTION

Can be found here.

This question is marked "community wiki".

asked 09 Nov '12, 12:40

19.0k348495533
accept rate: 37%

 1 @yyash here's the working code. I modified your code a bit. PLease compare it with your original code. http://ideone.com/mrDnXl And yes you don't have to use that count array to display the results of test cases all at once. You can output the results of each test case one by one. And try using ideone next time to share codes :D answered 25 Mar '17, 15:33 3★shraeyas 1.3k●1●5●18 accept rate: 10%

# include<string.h>

int result[100];

void main() { char J[100], S[100]; int T=0, i, j, count=0; scanf("%d", &T); while (T) { fflush(stdin); gets(J); gets(S); count = 0; for (i = 0; i < strlen(S); i++){ for (j = 0; j < strlen(J); j++){ if (S[i] == J[j]) { count++; break; }

        }
}
printf("\n%d", count);

T--;
}


}

answered 31 Aug '14, 01:33

1
accept rate: 0%

# define MAX 200

int main() { int t,j,s,i; char je[100],st[100]; scanf("%d",&t); while(t) { int h[MAX]={0}; int c=0; scanf("%s",je); scanf("%s",st); j=strlen(je); s=strlen(st); for(i=0;i<j;i++) h[je[i]]=je[i]; for(i=0;i<s;i++) { if(st[i]==h[st[i]]) c++; } printf("%d\n",c); t--; } return 0; }

what is wrong with this answer i dont understand i tried it on my computer and got the answers but here i am getting wrong answer

answered 16 Feb '17, 21:04

2★rusifan
1
accept rate: 0%

 0 @rusfian Your code works all fine EXCEPT for 1 category of corner case. Try changing string length to 101 and see the magic :) Here is the test case at str length of 100-  pre< input 1 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab > Output- 100  The reason that the error occurs is that the end of string is taken up by position c, so there is nothing to denote end of line or end of string, and hence it continues taking the other "aaaaaa...." as input of string 1. This results in string 2 being an empty string, and for it the condition is always true. Its an abnormal behaviour, and hence 1 extra character is always recommended. (Tested code by asking it to print je[101]...je[110] and got the chars of next line in it. Hence the above theory) answered 16 Feb '17, 21:49 13.8k●1●12●40 accept rate: 19%
 0 import java.util.; import java.lang.; class jewels { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc,i,len1,len2,j,k; tc = sc.nextInt(); int count[] = new int[tc]; for(i=0;i
 0 @yyash I believe that you don't have to delete the characters of stone. Meaning, multiple isntances of that stone occurring has to be counted. Your code fails in the following test cases- Input 1 abc aaa Output 1 Expected Output- 3  answered 25 Mar '17, 15:14 13.8k●1●12●40 accept rate: 19% Isn't the code giving compilation error? (25 Mar '17, 15:23) shraeyas3★ Its actually because of how the code is pasted here by him. I had to do corrections to resume checking....you can say I got experience of this now XD (since its a problem with >75% of codes copy pasted here) (25 Mar '17, 15:25)
 0 plz check my code as i am getting all cases right import java.util.Scanner; class codechef { public static void main(String[] args) { Scanner kb=new Scanner(System.in); int test=kb.nextInt(); while(test-->0) { String s1=kb.next(); String s2=kb.next(); int ans=0; for(int i=0;i

I know I can solve this question using traditional mathods but just for fun I used a bit of hashing. For some reason it keeps giving me a wrong answer even though I'm pretty sure about my solution. Here's the code.

# include<bits stdc++.h="">

using namespace std;

int main() { int t; cin>>t; while(t--) { string j,s; int count=0; cin>>j; cin>>s; int J[58]={0}; int S[58]={0}; for(int i=0;i<j.length();i++) {="" j[j[i]-'a']++;="" }="" for(int="" i="0;i&lt;s.length();i++)" {="" s[s[i]-'a']++;="" }="" for(int="" i="0;i&lt;58;i++)" count+="(S[i]">J[i] ? J[i] : S[i]); cout<<count<<endl;

    }


return 0;

}

answered 11 Sep '17, 04:36

101
accept rate: 0%

 0 If anyone who doesn't know much about hashset or any data structure , u can go do this ques by using simple brute force .U can go through my code. https://www.codechef.com/viewsolution/15487815 If u have any issue feel free to share. answered 21 Sep '17, 21:06 1●1 accept rate: 0%

//what is the problem in this programme.

# include <string.h>

using namespace std; int main() { int t,i,k,a; string s,j; cin>>t;

while(t--)
{
cin>>j>>s;
int p=0;
for(i=0;j[i]!='\0';i++)
{
for(k=0;s[k]!='\0';k++)
{
if(j[i]==s[k])
{
p++;
s[k]='{';
break;
}
}
}

cout<<p<<"\n";
}

return 0;


}

answered 07 Dec '17, 06:51

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:

×14,464
×3,207
×20
×13

question asked: 09 Nov '12, 12:40

question was seen: 4,220 times

last updated: 04 Jul, 08:32