fork(3) download
  1. //6 1
  2. //police
  3. //p m
  4.  
  5. //11 6
  6. //abacabadaba
  7. //a b
  8. //b c
  9. //a d
  10. //e g
  11. //f a
  12. //b b
  13. #include<bits/stdc++.h>
  14. int st[26][200000]={},tempst[200000],top[26]={};
  15. char a[200001];
  16. int main()
  17. {
  18. int n,m,i,v,j,top1,top2,v2;
  19. char b,c;
  20. scanf("%d%d",&n,&m);
  21. fflush(stdin);
  22. gets(a);
  23. //scanf("%s",a);
  24. for(i=0;i<n;i++)
  25. {
  26. //scanf("%c",&a[i]);
  27. if(a[i]==' ') continue;
  28. v=a[i]-'a';
  29. st[v][top[v]]=i;
  30. top[v]++;
  31. }
  32. for(i=0;i<m;i++)
  33. {
  34. fflush(stdin);
  35. scanf("%c %c",&b,&c);
  36. //printf("%c %c\n",b,c);
  37. v=b-'a';
  38. for(j=0;j<top[v];j++) a[st[v][j]]=c;
  39. v=c-'a';
  40. for(j=0;j<top[v];j++) a[st[v][j]]=b;
  41. v=b-'a';
  42. top1=top[v];
  43. for(j=0;j<top1;j++) tempst[j]=st[v][j];
  44. v2=c-'a';
  45. top2=top[v2];
  46. for(j=0;j<top2;j++) st[v][j]=st[v2][j];
  47. for(j=0;j<top1;j++) st[v2][j]=tempst[j];
  48. top[v]=top2;
  49. top[v2]=top1;
  50. }
  51. printf("%s",a);
  52. return 0;
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:22:11: error: 'gets' was not declared in this scope
     gets(a);
           ^
stdout
Standard output is empty