codeforces 236A-C语言解题报告

236题目网址

题目解析

1.输入字符串,判断其中不同的字符个数,奇偶输出不同的语句
2.使用冒泡排序去排序,当遇到s[k]!=s[k+1]时进行计数

代码

#include
#include
#include
int main()
{
     
	char s [100]={
     '\0'};
	int i,j,k,count=0;
	char c='\0';
	scanf("%s",s);

	for(i=0;i<strlen(s)-1;i++)
	{
     
		for(j=0;j<strlen(s)-1;j++)
		{
     
			if(s[j]>s[j+1])
			{
     
				c=s[j+1];
				s[j+1]=s[j];
				s[j]=c;
			}
		}
	}
	for(k=0;k<strlen(s);k++)
	{
     
		if(s[k]!=s[k+1])
		{
     
			++count;
		}
	}
	printf("%d\n",count);
	if(count%2==0)
	{
     
		printf("CHAT WITH HER!");
	}else
	{
     
		printf("IGNORE HIM!");
	}
	system("pause");
	getchar();
	return 0;
}

你可能感兴趣的:(考研C语言,c语言,字符串)