Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <numeric>
  4. #include <limits>
  5.  
  6. using namespace std;
  7.  
  8. /** 请完成下面这个函数,实现题目要求的功能 **/
  9. /** 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^ **/
  10. int GetLeastSquareGirth(int l, int w) {
  11. int a,b;
  12. if(l>w){
  13. a=l;
  14. b=w;
  15. }else{
  16. a=w;
  17. b=l;
  18. }
  19. if(b==0){
  20. return 0;
  21. }
  22. if (b==1){
  23. return 4*a;
  24. }else{
  25. int mod=a%b;
  26. return 4*b*(a-mod)/b+GetLeastSquareGirth(mod,b);
  27. }
  28.  
  29.  
  30. }
  31.  
  32. int main() {
  33. int res;
  34.  
  35. int _l;
  36. cin >> _l;
  37. cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
  38.  
  39.  
  40. int _w;
  41. cin >> _w;
  42. cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
  43.  
  44.  
  45.  
  46. res = GetLeastSquareGirth(_l, _w);
  47. cout << res << endl;
  48.  
  49. return 0;
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement