fork download
  1. /* add your value() based on this code */
  2. #include <stdio.h>
  3.  
  4. int value(int type, int width, int height, int length){
  5. int value;
  6. int type_value;
  7. switch(type){ //檢查輸入值
  8. case 79:
  9. type_value=30;
  10. break;
  11. case 47:
  12. type_value=10;
  13. break;
  14. case 29:
  15. type_value=4;
  16. break;
  17. case 82:
  18. type_value=5;
  19. break;
  20. case 26:
  21. type_value=3;
  22. break;
  23. case 22:
  24. type_value=9;
  25. break;
  26. default:
  27. return -1;
  28. }
  29. if(width<=0||height<=0||length<=0)
  30. return -2;
  31.  
  32. int a[3]={width, height, length};
  33. int temp;
  34. for(int n=1;n>=0;n--) //泡沫排序法
  35. for(int i=0;i<n;i++)
  36. if(a[i]<a[i+1]){
  37. temp=a[i];
  38. a[i]=a[i+1];
  39. a[i+1]=temp;
  40. }
  41.  
  42. for(int i=0;i<2;i++)
  43. while(a[i]%a[i+1]!=0){
  44. temp=a[i]%a[i+1];
  45. a[i]=a[i+1];
  46. a[i+1]=temp;
  47. }
  48. int one_value=type_value*a[2]*a[2]*a[2]*a[2]*a[2]*a[2];
  49. int how_many=(width/a[2])*(height/a[2])*(length/a[2]);
  50. value=one_value*how_many;
  51. return value;
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. int main ()
  63. {
  64. int type, width, height, length;
  65. scanf ( "%d%d%d%d", &type, &width, &height, &length );
  66. printf ( "%d", value ( type, width, height, length ) );
  67. return 0;
  68. }
Success #stdin #stdout 0s 5320KB
stdin
47 -3 18 81
stdout
-2