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;
}