Advertisement
Guest User

string

a guest
Sep 18th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int t1,i1,j1,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
  6.     a=0;
  7.     b=0;
  8.     c=0;
  9.     d=0;
  10.     e=0;
  11.     f=0;
  12.     g=0;
  13.     h=0;
  14.     i=0;
  15.     j=0;
  16.     k=0;
  17.     l=0;
  18.     m=0;
  19.     n=0;
  20.     o=0;
  21.     p=0;
  22.     q=0;
  23.     r=0;
  24.     s=0;
  25.     t=0;
  26.     u=0;
  27.     v=0;
  28.     w=0;
  29.     x=0;
  30.     y=0;
  31.     z=0;
  32.     cin>>t1;
  33.     char ch[1001],tem;
  34.     getchar();
  35.     for(i1=0;i1<t1;i1++)
  36.     {
  37.         //char ch[1001],tem;
  38.         //getchar();
  39.         gets(ch);
  40.         for(j1=0;ch[j1]!='\0';j1++)
  41.         {
  42.             if(ch[j1]=='a') a++;
  43.             else if(ch[j1]=='b') b++;
  44.             else if(ch[j1]=='c') c++;
  45.             else if(ch[j1]=='d') d++;
  46.             else if(ch[j1]=='e') e++;
  47.             else if(ch[j1]=='f') f++;
  48.             else if(ch[j1]=='g') g++;
  49.             else if(ch[j1]=='h') h++;
  50.             else if(ch[j1]=='i') i++;
  51.             else if(ch[j1]=='j') j++;
  52.             else if(ch[j1]=='k') k++;
  53.             else if(ch[j1]=='l') l++;
  54.             else if(ch[j1]=='m') m++;
  55.             else if(ch[j1]=='n') n++;
  56.             else if(ch[j1]=='o') o++;
  57.             else if(ch[j1]=='p') p++;
  58.             else if(ch[j1]=='q') q++;
  59.             else if(ch[j1]=='r') r++;
  60.             else if(ch[j1]=='s') s++;
  61.             else if(ch[j1]=='t') t++;
  62.             else if(ch[j1]=='u') u++;
  63.             else if(ch[j1]=='v') v++;
  64.             else if(ch[j1]=='w') w++;
  65.             else if(ch[j1]=='x') x++;
  66.             else if(ch[j1]=='y') y++;
  67.             else if(ch[j1]=='z') z++;
  68.         }
  69.  
  70.         for(int j2=0;ch[j2]!='\0';j2++){
  71.           for(j1=0;ch[j1]!='\0';j1++)
  72.           {
  73.             if((ch[j1]>ch[j1+1]) && (ch[j1+1]!='\0')){
  74.               tem=ch[j1];
  75.               ch[j1]=ch[j1+1];
  76.               ch[j1+1]=tem;
  77.             }
  78.           }
  79.         }
  80.         printf("#rearranged:  %s\n",ch);
  81.  
  82.        int k;
  83.        char cha[1001];
  84.        cha[0] = ch[0];
  85.        k=1;
  86.  
  87.        for(j1=1;ch[j1]!='\0';j1++){
  88.          if((ch[j1]!=ch[j1-1])){
  89.             cha[k] = ch[j1];
  90.             k++;
  91.          }
  92.  
  93.        }
  94.        cha[k] = '\0';
  95.        printf("#extracted:  %s\n",cha);
  96.  
  97.        for(j1=0;cha[j1]!='\0';j1++)
  98.         {
  99.  
  100.             if(cha[j1]=='a') printf("a = %d\n",a);
  101.             else if(cha[j1]=='b') printf("b = %d\n",b);
  102.             else if(cha[j1]=='c') printf("c = %d\n",c);
  103.             else if(cha[j1]=='d') printf("d = %d\n",d);
  104.             else if(cha[j1]=='e') printf("e = %d\n",e);
  105.             else if(cha[j1]=='f') printf("f = %d\n",f);
  106.             else if(cha[j1]=='g') printf("g = %d\n",g);
  107.             else if(cha[j1]=='h') printf("h = %d\n",h);
  108.             else if(cha[j1]=='i') printf("i = %d\n",i);
  109.             else if(cha[j1]=='j') printf("j = %d\n",j);
  110.             else if(cha[j1]=='k') printf("k = %d\n",k);
  111.             else if(cha[j1]=='l') printf("l = %d\n",l);
  112.             else if(cha[j1]=='m') printf("m = %d\n",m);
  113.             else if(cha[j1]=='n') printf("n = %d\n",n);
  114.             else if(cha[j1]=='o') printf("o = %d\n",o);
  115.             else if(cha[j1]=='p') printf("p = %d\n",p);
  116.             else if(cha[j1]=='q') printf("q = %d\n",q);
  117.             else if(cha[j1]=='r') printf("r = %d\n",r);
  118.             else if(cha[j1]=='s') printf("s = %d\n",s);
  119.             else if(cha[j1]=='t') printf("t = %d\n",t);
  120.             else if(cha[j1]=='u') printf("u = %d\n",u);
  121.             else if(cha[j1]=='v') printf("v = %d\n",v);
  122.             else if(cha[j1]=='w') printf("w = %d\n",w);
  123.             else if(cha[j1]=='x') printf("x = %d\n",x);
  124.             else if(cha[j1]=='y') printf("y = %d\n",y);
  125.             else if(cha[j1]=='z') printf("z = %d\n",z);
  126.         }
  127.  
  128.        a=0;
  129.     b=0;
  130.     c=0;
  131.     d=0;
  132.     e=0;
  133.     f=0;
  134.     g=0;
  135.     h=0;
  136.     i=0;
  137.     j=0;
  138.     k=0;
  139.     l=0;
  140.     m=0;
  141.     n=0;
  142.     o=0;
  143.     p=0;
  144.     q=0;
  145.     r=0;
  146.     s=0;
  147.     t=0;
  148.     u=0;
  149.     v=0;
  150.     w=0;
  151.     x=0;
  152.     y=0;
  153.     z=0;
  154.     }
  155.     return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement