@vijju1231
How to the output of this input will be 100 can you please explain it as there is only 1 b present in second string )
All 100 characters in 1st string are in 2nd string as well.
This is that implementation. Hope you like it.
t = int(input())
while(t>0):
j = input()
s = input()
j_dict = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0, 'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0}
s_dict = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0, 'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, 'M': 0, 'N': 0, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, 'S': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0}
for i in j:
j_dict[i] += 1
for i in s:
s_dict[i] += 1
count = 0
for alpha in s_dict.keys():
if(s_dict[alpha] >= 1):
if(j_dict[alpha] >= 1):
count += s_dict[alpha]
# print(j_dict)
# print(s_dict)
print(count)
t -= 1
Thanks man !
#include
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(tโ){
string s,s1;
cin>>s>>s1;
sort(s.begin(),s.end());
sort(s1.begin(),s1.end());
int i=0,j=0,c=0;
while(i<s.size()&&j<s1.size()){
if(s[i]==s1[j]){
c++;
i++;
j++;
}
else if(s[i]>s1[j]){
j++;
}
else if(s[i]<s1[j]){
i++;
}
}
cout<<c<<"\n";
}
return 0;
}
Can someone find error in this code???
Link to my solution: CodeChef: Practical coding for everyone
Cant figure out whatโs wrong in this simple code.
Please help.
#include <string.h>
#define MAX 101
int j[26*2];
int s[26*2];
int main(void) {
int t, i;
scanf("%d", &t);
while(t--){
char stone[MAX], jewel[MAX];
scanf("%s", jewel); scanf("%s", stone);
for(i = 0; i < 26*2; i++){
j[i] = 0; s[i] = 0;
}
for(i = 0; i < strlen(jewel); i++){
if(jewel[i] <= 'Z')
j[jewel[i] - 'A'] = 1;
else
j[jewel[i] - 'a' + 26] = 1;
}
for(i = 0; i < strlen(stone); i++){
if(stone[i] <= 'Z')
s[stone[i] - 'A'] = 1;
else
s[stone[i] - 'a' + 26] = 1;
}
int count = 0;
for(i = 0; i < 26*2; i++){
if(s[i] && j[i])
++count;
}
printf("%d\n", count);
}
return 0;
}
// First line contains an integer T denoting the number of test cases. Then follow T test cases. Each test case consists of two lines, each of which contains a string composed of English lower case and upper characters. First of these is the jewel string J and the second one is stone string S.
// You can assume that 1 <= T <= 100, 1 <= |J|, |S| <= 100
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cin.ignore();
while (nโ)
{int c=0;
string str, strj;
getline(cin, str);
getline(cin, strj);
{for(int k=0; k<str.length(); k++)
{ for(int i=0; i<strj.length(); i++)
if(str[k]==strj[i])
{ c++;
strj[i]='{';
break; }}
cout<<c<<endl;
}
}
}
why isnโt the code is giving output properly??
Can someone please help me understand what am i missing in this piece of code:
Blockquote
#include<bits/stdc++.h>using namespace std;
int main(){
int t; cin >> t; while(t--){ string J; cin >> J; string S; cin >> S; set<char> jewels; long int count = 0; // map<char, int> hm; for (int i = 0; i < J.length(); i++) { // hm[J[i]] += 1; jewels.insert(J[i]); } for (int i = 0; i < S.length(); i++) { if(jewels.find(S[i]) != jewels.end()){ count++; } } cout << count << endl; }
}
Here is the working code in C++
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
string j;
string s;
cin>>j>>s;
int i,k;
int count=0;
for (i = 0; i < s.size(); i++)
{
for (k = 0; k <j.size(); k++)
{
if (s[i]==j[k])
{
count++;
break;
}
}
}
cout<<count<<endl;
}
return 0;
}