码迷,mamicode.com
首页 > 其他好文 > 详细

将字符串中重复的字符打印出来

时间:2014-10-15 20:13:12      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:字符串   include   

bubuko.com,布布扣

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	char input[100];
	int count[26];
	int i=0,j=0,pos;
	char ans[26];
	memset(count,0,sizeof(count));
	cin>>input;
	while(input[i]!=‘\0‘)
	{
		pos=input[i]-‘a‘;
		count[pos]++;
		if(count[pos]==2)
			ans[j++]=input[i];	
		i++;
	}
	ans[j]=‘\0‘;
	for(i=0;i<strlen(ans);i++)
		printf("%c",ans[i]);
}


将字符串中重复的字符打印出来

标签:字符串   include   

原文地址:http://mrcage.blog.51cto.com/6836193/1564416

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!