(算法练习)——771. 宝石与石头(简单)

要求:
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);
}

发布了104 篇原创文章 · 获赞 3 · 访问量 1945

猜你喜欢

转载自blog.csdn.net/weixin_42377217/article/details/104033201
今日推荐