HUAWEI Written Test Questions: Extracting unique numbers

Title description

Enter an int integer and return a new integer without repeating numbers in the reading order from right to left.

Enter description:

Enter an int integer

Output description:

According to the reading order from right to left, return a new integer without repeated numbers

Example 1

Input

9876673

Output

37689
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    string str = "";
    for (int i = s.length() - 1; i >= 0; --i) {
        if (str.find(s[i]) == string::npos)
            str += s[i];
    }
    cout << str << endl;
    return 0;
}

 

Published 34 original articles · Like 10 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/weixin_41111088/article/details/104789206