Kiểm tra số hoán vị
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,j = 0, count1 = 0,count2 = 0,m,k=0;
cin>>n>>m;
int a[1000],b[1000];
while(n != 0)
{
int t = n % 10;
a[j++] = t;
count1++;
n = n / 10;
}
while(m != 0)
{
int t = m % 10;
b[k++] = t;
count2++;
m = m / 10;
}
for(int i = 0 ; i < count1 - 1; i++)
{
for(int p = i + 1; p < count1 ; p++)
{
if(a[i] < a[p])
{
int c = a[i];
a[i] = a[p];
a[i] = c;
}
}
}
for(int x = 0 ; x < count2 - 1; x++)
{
for(int y = x + 1; y < count2 ; y++)
{
if(b[x] < b[y])
{
int g = b[x];
b[x] = b[y];
b[y] = g;
}
}
}
bool f;
if(count1 == count2)
{
int x = 0 , i = 0;
while(x != count2 && i != count1)
{
if(a[i++] == b[x++])
f = true;
}
if(f == 1)
cout<<"YES";
if(f == 0)
cout<<"NO";
}
if(count1 != count2)
cout<<"NO"<<" ";
return 0;
}