fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n,m,s=0,d=0,v;
  5. char c;
  6. scanf("%d %d",&n,&m);
  7. string st; cin>>st;
  8.  
  9. if(st[0]=='.'){ d++; s++; }
  10. for(int i=1;i<n;i++)
  11. if(i==n-1 && st[i]=='.' && st[i-1]!='.') ;
  12. else if(st[i]=='.') { d++; if(st[i-1]!='.') s++; }
  13. else if( (i==1 && st[0]=='.') || (i!=1 && st[i-2]!='.') ) { d--; s--; }
  14.  
  15. for(i=0;i<m;i++){
  16. scanf("%d %c",&v,&c); // v-1 , c
  17. if(v==1){
  18. if(c!='.' && st[v-1]=='.' && st[v]=='.' ){
  19. if(st[v+1]=='.') d--;
  20. else { s--; d--; }
  21. }else if(c=='.' && st[v-1]!='.' && st[v]=='.'){
  22. if(st[v+1]!='.') { s++; d++; }
  23. else d++;
  24. }
  25. }else if(v==n){
  26. if(c!='.' && st[v-1]=='.' && st[v-2]=='.' ){
  27. if(st[v-3]=='.') d--;
  28. else { s--; d--; }
  29. }else if(c=='.' && st[v-1]!='.' && st[v-2]=='.'){
  30. if(st[v-3]!='.') { s++; d++; }
  31. else d++;
  32. }
  33. }else{
  34. if(c!='.' && st[v-1]=='.' ){
  35. if(st[v-2]=='.' && st[v]=='.')
  36. }else if(c=='.' && st[v-1]!='.'){
  37. if( (st[v-2]=='.' && st[v]!='.') || (st[v-2]!='.' && st[v]=='.') ){ d+=2; s++; }
  38. else if(st[v-2]=='.' && st[v]=='.'){
  39. if(v==2){
  40. if(st[v+1]=='.') d+=2;
  41. else{ d+=3; s++;}
  42. }else if(v==n-1){
  43. if(st[v-3]=='.') d+=2;
  44. else{ d+=3; s++;}
  45. }else{
  46.  
  47. }
  48. }
  49. }
  50. }
  51. }
  52. // printf("%d %d\n",d,s);
  53. /*
  54. for(i=0;i<m;i++){
  55. res=0,count=0;
  56. scanf("%d %c",&v,&c);
  57. s[v-1]=c;
  58. for(j=0;j<n;j++)
  59. if(s[j]=='.'){
  60. count++;
  61. if(j==(n-1) && count>=2) res+=(count-1);
  62. }else{
  63. if(count>=2) res+=(count-1);
  64. count=0;
  65. }
  66. printf("%d\n",res);
  67. }
  68. */
  69.  
  70. return 0;
  71. }
Compilation error #stdin compilation error #stdout 0s 3460KB
stdin
10 3
.b..bz.... // ..h..
1 h
3 c
9 f
compilation info
prog.cpp: In function 'int main()':
prog.cpp:15:6: error: 'i' was not declared in this scope
  for(i=0;i<m;i++){
      ^
prog.cpp:36:4: error: expected primary-expression before '}' token
    }else if(c=='.' && st[v-1]!='.'){
    ^
stdout
Standard output is empty