ccbeginner

Untitled

Dec 18th, 2021
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.07 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main ()
  4. {
  5.     char str[1025] = {0};
  6.     scanf("%[^\n]",str);
  7.     int n;
  8.     scanf("%d",&n);
  9.     for(int i=0;i<n;i++)
  10.     {
  11.         char instruction[100];
  12.         scanf("\n%s",instruction);
  13.         if(instruction[0]=='P')
  14.         {
  15.             printf("%s\n",str);
  16.         }
  17.         if(instruction[0]=='R'&&instruction[2]=='V')
  18.         {
  19.             int length=0;
  20.             while(1)
  21.             {
  22.                 if(str[length]=='\0')
  23.                 {
  24.                     length=length-1;
  25.                     break;
  26.                 }
  27.                 else length++;
  28.             }
  29.             int i=0;
  30.             int newstr[1025]={0};
  31.             for(int j=length;j>=0;j--)
  32.             {
  33.                 printf("%c",str[j]);
  34.                 newstr[i]=str[j];
  35.                 i++;
  36.             }
  37.             printf("\n");
  38.             newstr[i+1]='\0';
  39.             for(int i=0;newstr[i]!='\0';i++)
  40.             {
  41.                 str[i]=newstr[i];
  42.             }
  43.         }
  44.         if(instruction[3]=='L')
  45.         {
  46.             for(int i=0;str[i]!='\0';i++)
  47.             {
  48.                 if(str[i]>='A'&&str[i]<='Z')
  49.                 {
  50.                     str[i]+=32;
  51.                 }
  52.             }
  53.             for(int i=0;str[i]!='\0';i++)
  54.             {
  55.                 printf("%c",str[i]);
  56.             }
  57.             printf("\n");
  58.         }
  59.         if(instruction[3]=='U')
  60.         {
  61.             for(int i=0;str[i]!='\0';i++)
  62.             {
  63.                 if(str[i]>='a'&&str[i]<='z')
  64.                 {
  65.                     str[i]-=32;
  66.                 }
  67.             }
  68.             for(int i=0;str[i]!='\0';i++)
  69.             {
  70.                 printf("%c",str[i]);
  71.             }
  72.             printf("\n");
  73.         }
  74.         if(instruction[0]=='R'&&instruction[2]=='M')
  75.         {
  76.             char c;
  77.             scanf("%c",&c);
  78.             scanf("%c",&c);
  79.             int j=0;
  80.             for(int i=0;str[i]!='\0';i++)
  81.             {
  82.                 if(str[i]!=c)
  83.                 {
  84.                     printf("%c",str[i]);
  85.                     str[j]=str[i];
  86.                     j++;
  87.                 }
  88.             }
  89.             printf("\n");
  90.             str[j]='\0';
  91.         }
  92.         if(instruction[0]=='C')
  93.         {
  94.             char string[1025]={0};
  95.             int new=0;
  96.             for(int i=1,number=1;;i++)
  97.             {
  98.                 if(str[i]==str[i-1]) number++;
  99.                 else
  100.                 {
  101.                     string[new++]='-';
  102.                     string[new++]=str[i-1];
  103.                     string[new++]=number+48;
  104.                     number=1;
  105.                 }
  106.                 if(str[i]=='\0')
  107.                 {
  108.                     break;
  109.                 }
  110.             }
  111.             string[new+1]='\0';
  112.             for(int i=0;string[i]!='\0';i++)
  113.             {
  114.                 printf("%c",string[i]);
  115.             }
  116.             printf("\n");
  117.             for(int i=0;string[i]!='\0';i++)
  118.             {
  119.                 str[i]=string[i];
  120.             }
  121.            
  122.         }
  123.     }
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment