10.32查找仅有一个的字符
本文最后更新于 2727 天前,其中的信息可能已经有所发展或是发生改变。

内容纲要

[hide][code lang=”c”]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define tableSize 256 //创建一个哈希表,因为ASCII码表中只有0~255共256个字符。

char First_Char(char* pString)
{
if (!pString) //输入不合法
return 0;
int hashTable[tableSize];
for (int i = 0; i < tableSize; i++)
hashTable[i] = 0;
//确定字符串中每个字符出现的次数
char* pHashKey = pString;
while (*(pHashKey) != ‘\0’)
hashTable[*(pHashKey++)]++;
//找到字符串中只出现一次的那个字符
pHashKey = pString;
while (*pHashKey != ‘\0’)
{
if (hashTable[*pHashKey] == 1)
return*pHashKey;
pHashKey++;
}
//如果这个字符串为空,或者字符串中的每个字符都至少出现两次
return 0;
}

int main(void)
{
char str[1000]; //这个函数是在字符串特别大时建议使用,故定义一个大小为1000的数组
int a,i;
scanf("%d",&a);
for (i = 0; i < a; i++) {
scanf("%s",str);
if (First_Char(str) == 0)
printf("NO\n");
else
printf("%c\n", First_Char(str));
}
return 0;
}
[/code]
[/hide]

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇