Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6. int main()
  7. {
  8. int numbOfElements;
  9. int Data[1000];
  10. int Money_value[11]={1,2,4,8,16,32,64,128,256,512,1024};
  11. int Amount[11]= {0, 0,0,0, 0, 0, 0, 0, 0, 0, 0};
  12. int Used_values[11]={0,0,0,0, 0, 0, 0, 0, 0, 0, 0};
  13.  
  14.  
  15. cin>>numbOfElements;
  16. for(int i=0; i<numbOfElements; i++)
  17. {
  18. cin>>Data[i];
  19. if(Data[i]>=0)
  20. {
  21. for(int j=0; j<11; j++)
  22. {
  23. if(Data[i]==Money_value[j])
  24. Amount[j]++;
  25. }
  26. }
  27.  
  28. else if(Data[i]<0)
  29. {
  30. // for(int j=10; j>=0; j--)
  31. // {cout<<Money_value[j]<<"x"<<Amount[j]<<endl;}
  32. cout<<endl;
  33. cout<<"WORKING WITH: "<<Data[i]<<endl;
  34. for(int j=10; j>=0; j--)
  35. {
  36. if(Data[i]<0)
  37. Data[i]*=-1;//getting absolute value
  38. if(Data[i]>=Money_value[j] && Amount[j]>0)//money value detection
  39. {
  40. while(Data[i]>=Money_value[j] && Amount[j]!=0)
  41. {
  42. Used_values[j]++;
  43. Data[i]-=Money_value[j];
  44. Amount[j]--;
  45. }
  46.  
  47. }
  48. }
  49. for(int j=10; j>=0; j--)
  50. {
  51. if(Used_values[j]>0)
  52. {
  53. for(int a=0; a<Used_values[j]; a++)
  54. cout<<Money_value[j]<<" ";
  55. Used_values[j]=0;
  56. }
  57.  
  58. }
  59. }
  60. }
  61.  
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement