Monday, April 27, 2020

749A. Bachgold Problem Solution

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. int q=2;
  7. int c=0;
  8. cin>>n;
  9. if(n%2==0)
  10. {
  11. int p=n/2;
  12. cout<<p<<endl;
  13. for(int i=0;i<p;i++)
  14. cout<<2<<" ";
  15. }
  16.  
  17. else{
  18.  
  19. q=n/2-1;
  20. cout<<q+1<<endl;
  21. for(int j=0;j<q;j++)
  22. cout<<2<<" ";
  23.  
  24.  
  25. }
  26. if(n%2!=0)cout<<3;
  27.  
  28. return 0;
  29. }
  30.  

No comments:

Post a Comment

Aptitude test assistant programmer 2018

 #include <stdio.h> #include <stdlib.h> int main() { char str[100]; int i; int space=0;     printf("Enter a string\n")...