fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. long long int n,h,x;
  7. long long int carry=0;
  8. long long int a[100000];
  9. cin>>n>>h;
  10. for(long long int i=0;i<n;i++)
  11. {
  12. cin>>a[i];
  13. }
  14. long long int i=0;
  15. while(1){
  16. cin>>x;
  17. if(x==3 && a[i]>=1 && carry==0){
  18. a[i]--;
  19. carry=1;
  20. }
  21. }
  22. if(x==1 && i>=1){
  23. i--;
  24. }
  25. if(x==2 && i<n-1){
  26. i++;
  27. }
  28. if(x==4 && a[i]<h && carry==1){
  29. a[i]++;
  30. carry=0;
  31. }
  32. if(x==0){
  33. break;
  34. }
  35. }
  36. for(long long int i=0;i<n;i++){
  37. cout<<a[i]<<" ";
  38. }
  39. return 0;
  40. }
  41.  
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
7 4
3 1 2 1 4 0 1
3 2 2 2 2 4 1 3 1 4 0
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:33:13: error: break statement not within loop or switch
             break;
             ^~~~~
prog.cpp: At global scope:
prog.cpp:36:5: error: expected unqualified-id before ‘for’
     for(long long int i=0;i<n;i++){
     ^~~
prog.cpp:36:27: error: ‘i’ does not name a type
     for(long long int i=0;i<n;i++){
                           ^
prog.cpp:36:31: error: ‘i’ does not name a type
     for(long long int i=0;i<n;i++){
                               ^
prog.cpp:39:2: error: expected unqualified-id before ‘return’
  return 0;
  ^~~~~~
prog.cpp:40:1: error: expected declaration before ‘}’ token
 }
 ^
stdout
Standard output is empty