1. 1-Arrays Introduction
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <iostream>
  6. #include <algorithm>
  7. using namespace std;
  8. int main() {
  9. int n;
  10. cin>>n;
  11. int arr[n];
  12. for(int i=0;i<n;i++){
  13. cin>>arr[i];
  14. }
  15. for(int i=n-1;i>=0;i--){
  16. cout<<arr[i]<<" ";
  17. }
  18. return 0;
  19. }
  20. 2-Plus Minus
  21. #include<iostream>
  22. #include <iomanip>
  23. using namespace std;
  24. int main(){
  25. int n ;
  26. double pos=0,neg=0,zer=0;
  27. cin>>n;
  28. const int num = n-1;
  29. int arr[num] ;
  30. for (int i=0;i<n;i++){
  31. cin>>arr[i];
  32. if (arr[i]==0) zer++;
  33. if (arr[i]>0) pos++;
  34. if (arr[i]<0) neg++;
  35. }
  36. cout<<setprecision(6)<<fixed<<pos/(n)<<endl;
  37. cout<<setprecision(6)<<fixed<<neg/(n)<<endl;
  38. cout<<setprecision(6)<<fixed<<zer/(n)<<endl;
  39. return 0;
  40. }
  41. 3-Next Round (from: www.codeforces.com)
  42. #include <cmath>
  43. #include <cstdio>
  44. #include <vector>
  45. #include <iostream>
  46. #include <algorithm>
  47. using namespace std;
  48. int main() {
  49. int n,k,count=0;
  50. cin>>n>>k;
  51. int a[n];
  52. for(int i =0;i<n;i++){
  53. cin>>a[i];
  54. }
  55. for(int i =0;i<n;i++){
  56. if (a[i]>=a[k-1]&&a[i]>0) count++;
  57. }
  58. cout<<count;
  59. return 0;
  60. }
  61. 4-Stones on the Table (from: www.codeforces.com).
  62. #include <cmath>
  63. #include <cstdio>
  64. #include <vector>
  65. #include <iostream>
  66. #include <algorithm>
  67. using namespace std;
  68. int main() {
  69. int n,count=0 ;
  70. cin>>n ;
  71. char arr[n];
  72. for (int i =0;i<n;i++) cin>>arr[i];
  73. for (int i =0;i<n-1;i++){
  74. if (arr[i]==arr[i+1]) count++;
  75. }
  76. cout<<count;
  77. return 0;
  78. }
Comments powered by Disqus