codeforces 236A-C语言解题报告

【摘要】 236题目网址
题目解析
1.输入字符串,判断其中不同的字符个数,奇偶输出不同的语句 2.使用冒泡排序去排序,当遇到s[k]!=s[k+1]时进行计数
代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char s [100]={‘\0’};
int i,j,k,c…

236题目网址

题目解析

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

代码

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
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;
}

  
 

文章来源: blog.csdn.net,作者:DQ_CODING,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/qq_45402917/article/details/116376460

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享