题解 | #提取不重复的整数#
提取不重复的整数
https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
#include <stdio.h> #include <string.h> int main() { char str[10]; int repeat[10] = {0}; while (scanf("%s", str) != EOF) { // 注意 while 处理多个 case for (int i = strlen(str) - 1; i >= 0; i--) { if (repeat[str[i] - '0'] == 0) { printf("%c", str[i]); repeat[str[i] - '0']++; } } } return 0; }
总共就有十个字符0~9,用一个数组标记哪个字符已经打印过了,重复的就不打印,然后从最后一个字符往前遍历就行