山重水复

题目描述 Description

古语有云:“山重水复疑无路,柳暗花明又一村。” 重复有时候并不是好事,会遮掩住我们所需要的信息。现有一个字符串,其中可能有一些重复的字符,请去掉该字符串中重复字符,使任意一个出现的字符只保留一个,并按照原来的顺序输出去重过后的字符串。

输入描述 Input Description

输入为一行,为一个待去重的字符串(长度不超过1000)。

输出描述 Output Description

输出为一行,为去重过后的字符串。

样例输入 Sample Input

zxyzzaabcdxy

样例输出 Sample Output

zxyabcd

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     char s[1002];
 9     gets(s);
10     int len=strlen(s);
11     for(int i=0;i<len-1;i++)
12     {
13         for(int j=i+1;j<len;j++)
14         {
15             if(s[j]==s[i])
16                 s[j]='1';
17         }
18     }
19     int t=0;
20     while(s[t]!='\0')
21     {
22         if(s[t]!='1')
23             putchar(s[t]);
24         t++;
25     }
26     return 0;
27 }

猜你喜欢

转载自www.cnblogs.com/zhangjs73/p/10218112.html