字母c代表什么数字_字母C

字母c代表什么数字

Here is the program for anagram in c.
这是c中的字谜程序。
Two strings are said to be anagrams if by rearranging the characters of any one string will make both strings equal.
如果通过重新排列任一字符串的字符将使两个字符串相等,则两个字符串被称为字谜。
Example: 例:

“adsfa” and “sdfac” are not anagrams
“ adsfa”和“ sdfac”不是字谜

如何检查两个字符串是否是字谜? (How to Check two Strings are Anagrams or not?)

So what we will do is find the frequency of each characters in first and second string and store it in two arrays. Now we will check the frequency of each character in two strings by comparing the two arrays. If every character has same frequency then the strings are anagrams otherwise not. Below I have written a C program to implement this logic. If you are finding any difficulty then comment below, I will try to solve your problem.

因此,我们要做的是找到第一个和第二个字符串中每个字符的频率并将其存储在两个数组中。 现在,我们将通过比较两个数组来检查两个字符串中每个字符的频率。 如果每个字符具有相同的频率,则字符串是字谜,否则不是。 下面,我编写了一个C程序来实现此逻辑。 如果您发现任何困难,请在下面评论,我将尽力解决您的问题。

C语言的Anagram程序 (Anagram Program in C)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
//function to count the frequency of each character
void count_frequency(char str[],int s[])
{
	int i=0,j,count;
	while(str[i]!='\0')
	{
		j=0;
		count=0;
		while(str[j]!='\0')
		{
			if(str[i]==str[j])
				count++;
			j++;
		}
		
		s[str[i]-97]=count;
		i++;
	}
}
 
int main()
{
	char str1[100],str2[100];
	int i,j,flag=1,s1[26]={0},s2[26]={0};
	
	printf("Enter first string:");
	scanf("%s",str1);
	printf("Enter second string:");
	scanf("%s",str2);
	
	if(strlen(str1)!=strlen(str2))	//if the lengths of two strings are not equal
	{
		printf("\nStrings are not anagrams");
		exit(0);
	}
	
	count_frequency(str1,s1);
	count_frequency(str2,s2);
	
	for(i=0;i<26;++i)	//checking freuency of each character
	{
		if(s1[i]!=s2[i])
		{
			flag=0;
			break;
		}
	}
	
	if(flag)
		printf("\nStrings are anagrams");
	else
		printf("\nStrings are not anagrams");
		
	return 0;
}

Output:

输出:

C Program to Check two Strings are Anagrams or not, Anagram Program in C

翻译自: https://www.thecrazyprogrammer.com/2015/03/c-program-to-check-two-strings-are-anagrams-or-not.html

字母c代表什么数字

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值