要求:
https://leetcode-cn.com/problems/jewels-and-stones/
说明:
暴力做的。。。改天再试试hash表的做法
ps真的想说看别人用python 是真的好用啊,等有时间把算法用py过一遍
代码:
#include <stdio.h>
#include <string.h>
//暴力
int main(){
char str1[50];
char str2[50];
scanf("%s",str1);
scanf("%s",str2);
int count = 0;
int len1 = strlen(str1);
int len2 = strlen(str2);
for(int i = 0;i <len2;i++){
for(int j = 0;j <len1;j++){
if(str2[i]==str1[j]){
count++;
break;
}
}
}
printf("count=%d\n",count);
}