Advertisement
Centipede18

Hieu ;)

May 18th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. //#include<map.h>
  5. char s1[1000], s2[1000];
  6.  
  7. void nhap(){
  8. //  scanf("%s", &s1);
  9.     gets(s1);
  10.     gets(s2);
  11. }
  12.  
  13. int len(char s[]){
  14.     int x = 0;
  15.     while(s[x] != '\0'){
  16.         x++;
  17.     }
  18.     return x;
  19. }
  20.  
  21. int demTu(char s[]){
  22.     int count = 0;
  23.     for(int i=0; i<len(s)-1; i++){
  24.         if(s[i]!= ' ' && s[i+1] == ' ' || s[i+1] == '\0') count++;
  25.     }
  26.     return count;
  27. }
  28.  
  29. //void kituGiongNhau(char s[]){
  30. //  char b[300];
  31. //  long i, j, k, l = 0;
  32. //  for (i = 0; i < len(s); i++){
  33. //      k = 0;
  34. //      for(j = 0; j <= l; j++){
  35. //          if(s[j] == b[j]){
  36. //              k++;
  37. //          }
  38. //      }
  39. //      if(k == 0){
  40. //          k = l;
  41. //          for (j = i+1; j < len(s); j++){
  42. //              if(s[i] == s[j]){
  43. //                  k++;
  44. //                  printf("Ky tu %c da xuat hien: %ld lan \n", s[i], k);
  45. //              }
  46. //          }
  47. //      }
  48. //      b[l] = s[i];
  49. //      l++;
  50. //  }
  51. //}
  52.  
  53. void giongNhau(char s[]){
  54.     int dd[1000];
  55.     for(int i=0; i<len(s); i++){
  56.         dd[i]=1;
  57.     }
  58.     for(int i=0; i < len(s)-1; i++){
  59.         for(int j = i+1; j < len(s); j++){
  60.             if(s[i] == s[j] && dd[i] != 0){
  61.                 dd[i]++;
  62.                 dd[j]=0;
  63.             }
  64.         }
  65.     }
  66.     for(int i=0; i<len(s); i++){
  67.         if(dd[i]!=0) printf("%c: %d\n", s[i], dd[i]);
  68.     }
  69. }
  70. //  std::map<char, int> myMap;
  71. //void giongNhauCach2(char s[]){
  72. //  for(int i=0; i<len(s); i++){
  73. //      myMap[s[i]]++;
  74. //  }
  75. //  for(int i=0; i<len(s); i++){
  76. //      if(myMap[s[i]] != 0){
  77. //          printf("%c: %d", myMap[s[i]]);
  78. //          myMap[s[i]]=0;
  79. //      }
  80. //  }
  81. //}
  82.  
  83. void timKiTu(char s[], char s2[]){
  84.     int count = 0;
  85.     for(int i=0; i<len(s); i++){
  86.         if(s[i] == s2[0]){
  87.             printf("So *%c* o vi tri: %d\n", s[i], i);
  88.             count++;
  89.         }
  90.     }
  91.     if(count == 0){
  92.         printf("Ky tu muon tim khong co trong chuoi");
  93.     }
  94. }
  95.  
  96. char *right_(char s[], int n){
  97.     if(n >= len(s)) return s;
  98.     else{
  99.         char *s1;
  100.         s1 = new char[n+1];
  101.         for(int i=0; i<n; i++){
  102.             s1[i] = s[len(s)-n+i];
  103.         }
  104.         s1[n] = '\0';
  105.         return s1;
  106.     }
  107. }
  108.  
  109. char *left_(char s[], int n){
  110.     if(n >= len(s)) return s;
  111.     else{
  112.         char *s1;
  113.         s1 = new char[n+1];
  114.         for(int i=0; i<n; i++){
  115.             s1[i] = s[i];
  116.         }
  117.         s1[n] = '\0';
  118.         return s1;
  119.     }
  120. }
  121. int timxau(char s[], char s3[], int vtdau, int vtcuoi){
  122.     for(int i=0; s[i] != '\0'; i++){
  123.         if(s[i] == s3[0]){
  124.             int check = 1;
  125.             int j = 1;
  126.             while(s3[j] != '\0'){
  127.                 if(s[i+j] != s3[j]){
  128.                     check = 0;
  129.                     break;
  130.                 }
  131.                 j++;
  132.             }
  133.             if(check == 1){
  134.                 vtdau = i;
  135.                 vtcuoi = i+j-1;
  136.                 return 1;
  137.             }
  138.         }
  139.     }
  140.     return 0;
  141. }
  142.  
  143. char hoa(char s[]){
  144.     for(int i=0; i < len(s); i++){
  145.         if(s[i] >= 'a' && s[i] <= 'z'){
  146.             s[i] -= 32;
  147.         }
  148.     }
  149.     printf("\n%s", s);
  150. }
  151.  
  152. main()
  153. {
  154.     nhap();
  155. //  gets(s1);
  156. //  printf("%d", len(s1));
  157.     giongNhau(s1);
  158. //  giongNhauCach2(s1);
  159.     timKiTu(s1, s2);
  160.     printf("Lay tu ben phai: %s\n", right_(s1, 2));
  161.     printf("Lay tu ben trai: %s\n", left_(s1, 2));
  162.     printf("giong: %d", timxau(s1, s2, 0, len(s1)));
  163.     hoa(s1);
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement