剑指Offer:第一个只出现一次的字符
2014-07-24 01:01
253 查看
题目:在字符串中找出第一个只出现一次的字符。如输入"abaccdeff",这输出'b'
// 第一个只出现一次的字符 #include <stdio.h> char first_not_repeat_char(char *s) { int count[256]={0}; char *pkey; if( s==NULL ) { printf("The string should not be NULL\n"); return '\0'; } for(pkey=s; *pkey != '\0'; pkey++) count[*pkey]++; for(pkey=s; *pkey != '\0'; pkey++) if( count[*pkey] == 1 ) return *pkey; return '\0'; } int main(void) { char s[1001]; printf("Please input a string: "); scanf("%s",s); char first = first_not_repeat_char(s); if(first != '\0') printf("First not repeat char is: %c\n",first); else printf("Not found\n"); char *p=0; return 0; }
相关文章推荐
- 剑指offer系列之33:第一个只出现一次的字符
- 剑指Offer(java版):第一个只出现一次的字符
- 剑指offer—第一个只出现一次的字符位置
- 《剑指offer》-找到字符串中第一个只出现一次的字符,并返回它的位置
- 《剑指Offer》面试题:找到第一个只出现一次的字符
- [剑指Offer]第一个只出现一次的字符
- 《剑指offer》——第一个只出现一次的字符
- python剑指offer系列第一个只出现一次的字符
- 剑指Offer------第一个只出现一次的字符
- 《剑指offer》-第一个只出现一次的字符位置
- 剑指offer(19)-第一个只出现一次的字符
- 第一个只出现一次的字符 (剑指offer)
- 剑指offer-面试题35-第一个只出现一次的字符
- 剑指Offer系列-面试题35:第一个只出现一次的字符
- 剑指offer-35 第一个只出现一次的字符
- 剑指offer----第一个只出现一次的字符
- 剑指offer系列之三十三:第一个只出现一次的字符
- 剑指offer——第一个只出现一次的字符
- 剑指offer 面试题35 字符串中第一个出现一次的字符
- (剑指offer)丑数 寻找第一个只出现一次的字符