题解 | #提取不重复的整数#

提取不重复的整数

https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1

#include <cmath>
#include <iostream>
using namespace std;

int main() {
    int a, b;
    int arr[10] = {0};
    int i = 0;
    cin >> a;
    while (a > 0) { // 注意 while 处理多个 case
        b = a%10;
        a = a/10;
        if(arr[b] == 0)
        { 
            ++i;
            arr[b] = i ;
        }
    }
    b = 0;
    for(int j = 0; j < 10; ++j)
    {   if(arr[j] != 0)
        {
            b += j*(pow(10, i-arr[j])) ;
        }
    }
    cout<<b<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务