编程题【字符集合】

输入描述:
每组数据输入一个字符串,字符串最大长度为100,且只包含字母,不可能为空串,区分大小写。
输出描述:
每组数据一行,按字符串原有的字符顺序,输出字符集合,即重复出现并靠后的字母不输出。
示例1

输入

abcqweracb

输出

abcqwer

思路:用数组记录当前字母是否输出过
 1 #include <iostream>
 2 #include<bits/stdc++.h>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     string in;
 9     while (cin >> in)
10     {
11         int asc[125];
12         memset(asc,0,sizeof(asc));//要先把数组置零
13         for (int i=0; i<in.size(); i++)
14         {
15             int id = in[i];
16             if (!asc[id])//若该字母还没输出过则进行输出
17             {
18                 printf("%c",in[i]);
19                 asc[id] = 1;//打上已有标记
20             }
21         }
22         printf("
");
23     }
24 
25     return 0;
26 }
原文地址:https://www.cnblogs.com/hemeiwolong/p/12287283.html