fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. int t,n,sl;
  5. string b,slowo=" ";
  6. char l;
  7. cin>>t;
  8. for(int i=0;i<t;i++){
  9. cin>>b;
  10. sl=slowo.length()-1;
  11. if(b=="DODAJ"){
  12. cin>>l;
  13. if(slowo[sl]!=0){
  14. slowo=slowo+l;
  15. }
  16. else{
  17. slowo[sl]=l;
  18. }
  19.  
  20. }
  21. else if(b=="USUN"){
  22. cin>>n;
  23. for(int j=0;j<n;j++){
  24. if(sl-j>=0){
  25. slowo[sl-j]=0;
  26. }
  27. }
  28. }
  29. else if(b=="ZAMIEN"){
  30. cin>>l;
  31. if(slowo.length()>1){
  32. slowo[sl]=l;
  33. }
  34.  
  35. }
  36.  
  37. }
  38. for(int i=0;i<sl+2;i++){
  39. if(t==0){
  40. break;
  41. }
  42. if(slowo[i]!=32&&slowo[i]!=0){
  43. cout<<slowo[i];
  44. }
  45. }
  46. }
  47.  
Success #stdin #stdout 0.01s 5472KB
stdin
5
ZAMIEN P
DODAJ A
USUN 10
DODAJ C
DODAJ A
stdout
CA