trucngoanngoan
ví dụ : 123 213 321NguyenAnhQuan
c_cpp
a year ago
1.0 kB
7
Indexable
#include <bits/stdc++.h> #define ll long long #define LIM 1005 #define X first #define Y second #define EL cout<<"\n" using namespace std; // Tìm các số có chung chữ số int encode(int x) { int d[15]; int k = 0; while (x > 0) { d[++k] = (x % 10); x /= 10; } sort(d + 1, d + k + 1); int res = 0; for (int i = 1; i <= k; i++) res = res * 10 + d[i]; return res; } void Fun(int a[], int n) { int code[LIM]; for (int i = 1; i <= n; i++) code[i] = encode(a[i]); for (int i = 1; i < n; i++) { if (code[i] == 0) continue; int flag = 0; for (int j = i + 1; j <= n; j++) if (code[i] == code[j]) { flag = 1; cout << a[j] << " "; code[j] = 0; } if (flag) cout << a[i]; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; int a[LIM]; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; Fun(a, n); return 0; }
Editor is loading...
Leave a Comment