fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void DELETE(char *TEXT, int DEL)
  6. {
  7. int N=strlen(TEXT);
  8. for(int i=DEL;i<N;i++)
  9. {
  10. TEXT[i-1]=TEXT[i];
  11. }
  12. TEXT[N-1]='\0';
  13. }
  14.  
  15. void INSERT(char *TEXT, int INS, char ITEM)
  16. {
  17. int N=strlen(TEXT);
  18. for(int i=N;i>=INS-1;i--)
  19. {
  20. TEXT[i]=TEXT[i-1];
  21. }
  22. TEXT[INS-1]=ITEM;
  23. TEXT[N+1]='\0';
  24. }
  25.  
  26. int main()
  27. {
  28. string s="\n0.DELETION\n1.INSERTION\nchoose any: ";
  29.  
  30. char TEXT[100],ITEM;
  31. int t,DEL,INS;
  32. scanf("%s",TEXT);
  33. while(cout<<s,cin>>t)
  34. {
  35. if(t)
  36. {
  37. cin>>INS>>ITEM;
  38. INSERT(TEXT,INS,ITEM);
  39. }
  40. else
  41. {
  42. cin>>DEL;
  43. DELETE(TEXT,DEL);
  44. }
  45. cout<<TEXT<<endl;
  46. }
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5284KB
stdin
AABABDA
0
3
0
4
1
2 B
1
4 C
stdout
0.DELETION
1.INSERTION
choose any: AAABDA

0.DELETION
1.INSERTION
choose any: AAADA

0.DELETION
1.INSERTION
choose any: ABAADA

0.DELETION
1.INSERTION
choose any: ABACADA

0.DELETION
1.INSERTION
choose any: