please solve this

write a code that get a number x from the user(with this assumption that x has no any repeated digits)and print out the first larger number that is more than x.and if there doesn't exist any number by the situation print 0:
input 1:
42315
output 1:
42351
input 2:
764
output 2:
0
closed account (48T7M4Gy)
You have to write the code, or some sort of attempt at it, and show us where you are not clear.
#include <iostream>
#include <time.h>
#include <cstdlib>
using namespace std;
int fact(int n)
{
if(n==1)
return 1;
else
return n*fact(n-1);
}
void quickSort(int arr[],int left,int right)
{
int i=left ,j=right;
int tmp;
int pivot=arr[(left+right)/2];
while(i<=j)
{
while(arr[i]<pivot)
i++;
while(arr[j]>pivot)
j--;
if(i<=j){
tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
i++;
j--;
}
}
if(left<j)
quickSort(arr,left,j);
if(i<right)
quickSort(arr,i,right);
}
int b_search(int a[],int low,int high,int x){
if(low>=high)
return -1;
int mid=(low+high)/2;
if(a[mid]==x)
return mid;
else if(a[mid]>x)
b_search(a,low,mid-1,x);
else if(a[mid]<x)
b_search(a,mid+1,high,x);
}
main()
{
srand(time(NULL));
int n,dig=0;
cin>>n;
int m=n,p=n;
while(n>0){
dig++;
n/=10;
}
int digit[dig];
for(int i=0;i<dig;i++){
digit[i]=m%10;
m/=10;
}
int num,alist[fact(dig)];
for(int j=0;j<dig;j++){
num=0;
int t=rand()%(dig+1);
num+=digit[t];
num*=10;
alist[j]=num;
}
quickSort(alist,0,fact(dig));
b_search(alist,0,fact(dig),p);
if(mid=fact(dig))
cout<<"0";
else
cout<<mid+1;
}
please correct me.
I can't solve.
thanks.
Regards.
Can anyone solve this for me please?????
Thanks a lot
You're not really being clear here, do you want to swap the last 2 digits of the number or what exactly do you wanna do ?
Topic archived. No new replies allowed.