Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int numbOfElements;
- int Data[1000];
- int Money_value[11]={1,2,4,8,16,32,64,128,256,512,1024};
- int Amount[11]= {0, 0,0,0, 0, 0, 0, 0, 0, 0, 0};
- int Used_values[11]={0,0,0,0, 0, 0, 0, 0, 0, 0, 0};
- cin>>numbOfElements;
- for(int i=0; i<numbOfElements; i++)
- {
- cin>>Data[i];
- if(Data[i]>=0)
- {
- for(int j=0; j<11; j++)
- {
- if(Data[i]==Money_value[j])
- Amount[j]++;
- }
- }
- else if(Data[i]<0)
- {
- // for(int j=10; j>=0; j--)
- // {cout<<Money_value[j]<<"x"<<Amount[j]<<endl;}
- cout<<endl;
- cout<<"WORKING WITH: "<<Data[i]<<endl;
- for(int j=10; j>=0; j--)
- {
- if(Data[i]<0)
- Data[i]*=-1;//getting absolute value
- if(Data[i]>=Money_value[j] && Amount[j]>0)//money value detection
- {
- while(Data[i]>=Money_value[j] && Amount[j]!=0)
- {
- Used_values[j]++;
- Data[i]-=Money_value[j];
- Amount[j]--;
- }
- }
- }
- for(int j=10; j>=0; j--)
- {
- if(Used_values[j]>0)
- {
- for(int a=0; a<Used_values[j]; a++)
- cout<<Money_value[j]<<" ";
- Used_values[j]=0;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement