Răspuns :
#include<iostream>
#include<math.h>
using namespace std;
int GetSize(int Nr);
int GetNrByPlace(int Nr,int Loc);
int main(){
int n=0,Temp=0,
MaxNr=0,
Loc=1;
cin>>n; Temp=n;
while(n!=0){
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)>MaxNr){
MaxNr=GetNrByPlace(n,x);
Loc=x;
}
}
if(MaxNr!=0) {
cout<<MaxNr<<",";
n-=(int)MaxNr*pow(10,(double)Loc-1) ;
MaxNr=0;
}
}
//============If n had a 0 or more add them========
n=Temp;
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)==0) cout<<"0,";
}
system("pause");
return 0;
}
int GetSize(int Nr){
int Size=0;
while(Nr!=0){
Size++; Nr/=10;
}
return Size;
}
int GetNrByPlace(int Nr,int Loc){
int Count=0;
while(Nr!=0){
Count++;
if(Count==Loc) {
return Nr%10;
continue;
}
Nr/=10;
}
}
Vezi ca algoritmul pune o virgula in plus. Te las pe tine sa o rezolvi (cu un if).
#include<math.h>
using namespace std;
int GetSize(int Nr);
int GetNrByPlace(int Nr,int Loc);
int main(){
int n=0,Temp=0,
MaxNr=0,
Loc=1;
cin>>n; Temp=n;
while(n!=0){
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)>MaxNr){
MaxNr=GetNrByPlace(n,x);
Loc=x;
}
}
if(MaxNr!=0) {
cout<<MaxNr<<",";
n-=(int)MaxNr*pow(10,(double)Loc-1) ;
MaxNr=0;
}
}
//============If n had a 0 or more add them========
n=Temp;
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)==0) cout<<"0,";
}
system("pause");
return 0;
}
int GetSize(int Nr){
int Size=0;
while(Nr!=0){
Size++; Nr/=10;
}
return Size;
}
int GetNrByPlace(int Nr,int Loc){
int Count=0;
while(Nr!=0){
Count++;
if(Count==Loc) {
return Nr%10;
continue;
}
Nr/=10;
}
}
Vezi ca algoritmul pune o virgula in plus. Te las pe tine sa o rezolvi (cu un if).