1. LAB 6:
  2. Q1: A. Soldier and Bananas :
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <iostream>
  7. #include <algorithm>
  8. using namespace std;
  9. int main() {
  10. int cost,num,has,i=1,sum=0;
  11. cin >>cost>>has>>num;
  12. while (i<=num)
  13. {
  14. sum=sum+(i*cost);
  15. i++;
  16. }
  17. cout << sum -has;
  18. return 0;
  19. }
  20. ***************************************************************************************************
  21. Q2 :The Block Game
  22. #include <iostream>
  23. #include <algorithm>
  24. using namespace std;
  25. int main() {
  26. int n,i=1,w,c=1;
  27. cin>>n;
  28. while (i<=n)
  29. {
  30. cin >>w;
  31. int w1=w%10 , w2=w%100-w1;
  32. int w3=(w%1000-w%100)/100;
  33. if (w<100)
  34. {
  35. if (w1==w2/10)
  36. cout << "wins"<<endl;
  37. else cout << "losses"<<endl;
  38. }
  39. else{
  40. if (w1==w3)
  41. cout << "wins"<<endl;
  42. else cout << "losses"<<endl;
  43. }
  44. i++;
  45. }
  46. return 0;
  47. }
  48. ***************************************************************************************************
  49. Q3: A. Fox And Snake :
  50. #include <iostream>
  51. #include <algorithm>
  52. using namespace std;
  53. int main() {
  54. int i,j,n,m;
  55. cin>>n>>m;
  56. for (i=1;i<=n;i++){
  57. for (j=1;j<=m;j++)
  58. if (i%2==1)
  59. cout << "#";
  60. else if ((i%2==0)&&(i%4!=0))
  61. {if (j!=m)
  62. cout << ".";
  63. else cout <<"#";
  64. }
  65. else if (i%4==0)
  66. {
  67. if (j==1)
  68. cout <<"#";
  69. else cout << ".";
  70. }
  71. cout << endl;
  72. }
  73. return 0;
  74. }
  75. ******************************************JEBRIL_MEJDALAWI********************************************
Comments powered by Disqus