Chinaunix首页 | 论坛 | 博客
  • 博客访问: 640215
  • 博文数量: 171
  • 博客积分: 2246
  • 博客等级: 大尉
  • 技术积分: 1574
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-31 11:45
文章分类

全部博文(171)

文章存档

2018年(3)

2017年(4)

2015年(1)

2014年(20)

2013年(57)

2012年(86)

分类: LINUX

2013-10-14 17:19:16


  1. //找出一个字符串中第一个重复出现的字符
  2. //超级牛逼的方法
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>//memset
  6. #include <memory.h>
  7. #include <iostream>
  8. #define N 256

  9. char Find(char str[], int n)
  10. {
  11.     char temp[N] = {0};
  12.     char dst;
  13.     //memset((void *)temp,0x00,N*sizeof(char));

  14.     for(int i=0; i < n; ++i)
  15.     {
  16.         int num = (int)str[i];
  17.         if(temp[num] == 0)
  18.         {
  19.             temp[num] = num;
  20.         }
  21.         else
  22.         {
  23.             dst = temp[num];
  24.             //std::cout << dst ;
  25.             break;
  26.         }
  27.     }
  28.     return dst;
  29. }

  30. void main()
  31. {
  32.     char s[]="abcdefefddaddf";
  33.     //char ch;
  34.     char a =Find(s,sizeof(s)/sizeof(char));
  35.     std::cout << a;
  36. }




FROM:http://blog.csdn.net/bxyill/article/details/7495503
阅读(669) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~