题解 | #提取不重复的整数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
用了一个数组存储,一个数组标记,一个计数器,str[j]是字符要转化成数字
#include<iostream> using namespace std; int main() { string str; int ans[10], cnt[10] = { 0 }, count = 0; cin >> str; for (int j = str.size() - 1; j >= 0; j--) { int t = str[j] - 48; if (!cnt[t]) { ans[count] = t; cnt[t] = 1, count++; } } for (int i = 0; i < count; i++) { cout << ans[i]; } return 0; }