Advertisement
anhkiet2507

XauKiTu

May 28th, 2021
2,540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.46 KB | None | 0 0
  1. //CHUYỂN THÀNH CHỮ HOA
  2. #include<stdio.h>
  3. #include<ctype.h>
  4. #include<math.h>
  5. #include<string.h>
  6. int main(){
  7.     int i=0;
  8.     char str[100];
  9.     gets(str);
  10.     char c;
  11.     while (str[i])
  12.   {
  13.     c=str[i];
  14.     putchar (toupper(c));
  15.     i++;
  16.   }
  17.     return 0;
  18. }
  19. //ĐẾM KÝ TỰ
  20. #include<stdio.h>
  21. #include<ctype.h>
  22. #include<math.h>
  23. #include<string.h>
  24. int main(){
  25.     int i=0,chucai=0, chuso=0, kitukhac=0;
  26.     char str[100];
  27.     gets(str);
  28.     char c;
  29.     while (str[i])
  30.   {
  31.     c=str[i];
  32.     if(isalpha(c)){
  33.         chucai++;
  34.     } else {
  35.         if(isdigit(c)){
  36.         chuso++;
  37.         } else {
  38.             kitukhac++;
  39.         }
  40.     }
  41.     i++;
  42.   }
  43.     printf("%d %d %d", chucai, chuso, kitukhac);
  44.     return 0;
  45. }
  46. //LOẠI BỎ TỪ TRONG XÂU
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50.  
  51. void doAction(char *src, int pos, int len) {
  52.     int i;
  53.     int size = strlen(src);
  54.     for(i = pos; i <= size - len; i++) {
  55.         src[i] = src[i + len];
  56.     }
  57. }
  58.  
  59. void removeStr(char *src, char *token) {
  60.     int i;
  61.     int len = strlen(token);
  62.     for(i = 0; src[i] != '\0'; i++) {
  63.         if(strstr(&src[i], token) == &src[i]) {
  64.             doAction(src, i, len);
  65.             i --;
  66.         }
  67.     }
  68. }
  69.  
  70. int main(){
  71.     char input[1000];
  72.     char token[100];
  73.     fgets(input, 999, stdin);
  74.     fgets(token, 99, stdin);
  75.    
  76.     int len = strlen(token);
  77.     if(len > 0) {
  78.         token[len-1] = '\0';
  79.     }
  80.    
  81.     int size = strlen(input);
  82.     if(size > 0) {
  83.         input[size-1] = '\0';
  84.     }
  85.    
  86.     removeStr(input, token);
  87.     puts(input);
  88.    
  89.     return 0;
  90. }
  91. //LOẠI CÁC TỪ TRÙNG NHAU
  92. #include <stdio.h>
  93. #include <stdlib.h>
  94. #include <string.h>
  95.  
  96. int main ()
  97. {
  98.     char str[100], word[100], twoD[10][30];
  99.     int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, l = 0;
  100.     gets (str);
  101.  
  102.     for (i = 0; str[i] != '\0'; i++)
  103.     {
  104.         if (str[i] == ' ')
  105.         {
  106.             twoD[k][j] = '\0';
  107.             k ++;
  108.             j = 0;
  109.         }
  110.         else
  111.         {
  112.             twoD[k][j] = str[i];
  113.             j ++;
  114.         }
  115.     }
  116.  
  117.     twoD[k][j] = '\0';
  118.  
  119.     j = 0;
  120.     for (i = 0; i < k; i++)
  121.     {
  122.         int present = 0;
  123.         for (l = 1; l < k + 1; l++)
  124.         {
  125.             if (twoD[l][j] == '\0' || l == i)
  126.             {
  127.                 continue;
  128.             }
  129.  
  130.             if (strcmp (twoD[i], twoD[l]) == 0) {
  131.                 twoD[l][j] = '\0';
  132.                 present = present + 1;
  133.             }
  134.         }
  135.  
  136.     }
  137.  
  138.     j = 0;
  139.  
  140.     for (i = 0; i < k + 1; i++)
  141.     {
  142.         if (twoD[i][j] == '\0')
  143.             continue;
  144.         else
  145.             printf ("%s ", twoD[i]);
  146.     }
  147.  
  148.     printf ("\n");
  149.  
  150.     return 0;
  151. }
  152. //ĐẾM SỐ TỪ TRONG XÂU
  153. #include<stdio.h>
  154. int demkitu(char s[])
  155. {
  156.     int i=0;
  157.     while (s[i]!='\0')
  158.     {
  159.         i++;
  160.     }
  161.     return i;
  162. }
  163.  
  164. int main()
  165. {
  166.     int n;
  167.     scanf("%d\n", &n);
  168.  
  169.     for (int i=1; i<=n; i++)
  170.     {
  171.         char s[201];
  172.         gets(s);
  173.  
  174.         int last=demkitu(s)-1;
  175.  
  176.         while (s[last]==' ') last--;
  177.  
  178.         int count=0;
  179.         for (int j=0; j<=last; j++)
  180.         {
  181.             if (s[j]!=' ' && s[j+1]==32) count++;
  182.  
  183.             if (s[j]!=' ' && s[j+1]=='\0') count++;
  184.         }
  185.         printf("%d", count);
  186.         printf("\n");
  187.     }
  188.     return 0;
  189. }
  190. //SỐ ĐẸP 1
  191. #include<stdio.h>
  192. #include<string.h>
  193. int main(){
  194.     int t;
  195.     scanf("%d", &t);
  196.     while(t--){
  197.         char so[500];
  198.         scanf("%s", so);
  199.         int dodai = strlen(so);
  200.         int i,le=0,check=0;
  201.         for(i = 0; i<dodai; i++){
  202.             if(((int)so[i]-48)%2==1){
  203.                 le++;
  204.             }
  205.         }
  206.         for(i = 0; i<(dodai/2);i++){
  207.             if(((int)so[i]-48)!=((int)so[dodai-i-1])){
  208.                 check++;
  209.             }
  210.         }
  211.         if(check!=0&&le==0){
  212.             printf("YES");
  213.         } else {
  214.             printf("NO");
  215.         }
  216.         printf("\n");
  217.     }
  218.     return 0;
  219. }
  220. //SỐ ĐẸP 2
  221. #include<stdio.h>
  222. #include<string.h>
  223. int main(){
  224.     int t;
  225.     scanf("%d", &t);
  226.     while(t--){
  227.         char so[500];
  228.         scanf("%s", so);
  229.         int dodai = strlen(so);
  230.         int i,check1=0,check2=0;
  231.         if(((int)so[0]-48)==8&&((int)so[dodai-1]-48)==8){
  232.             check1=1;  
  233.         }
  234.         int tong=0;
  235.         for(i=0; i<dodai; i++){
  236.             tong=tong+((int)so[i]-48);
  237.         }
  238.         if(tong%10==0){
  239.             check2=1;
  240.         }
  241.         if(check1==1&&check2==1){
  242.             printf("YES");
  243.         }else {
  244.             printf("NO");
  245.         }
  246.         printf("\n");
  247.     }
  248.     return 0;
  249. }
  250. //SỐ ĐẸP 3
  251. #include<stdio.h>
  252. #include<string.h>
  253. int SNT(int n){
  254.     if(n<2){
  255.         return 0;
  256.     }
  257.     int count = 0,j;
  258.     for(j=2; j<=sqrt(n); ++j){
  259.         if(n%j==0){
  260.             count++;
  261.         }
  262.     }
  263.     if(count==0){
  264.         return 1;
  265.     } else {
  266.         return 0;
  267.     }
  268. }
  269. int main(){
  270.     int t;
  271.     scanf("%d", &t);
  272.     while(t--){
  273.         char so[500];
  274.         scanf("%s", so);
  275.         int dodai = strlen(so);
  276.         int i,check1=0,check2=0;
  277.         for(i = 0; i<(dodai/2);i++){
  278.             if(((int)so[i]-48)!=((int)so[dodai-i-1]-48)){
  279.                 check1++;
  280.             }
  281.         }
  282.         for(i = 0; i<dodai; i++){
  283.             if(SNT((int)so[i]-48)==0){
  284.                 check2++;
  285.             }
  286.         }
  287.         if(check1==0&&check2==0){
  288.             printf("YES");
  289.         }else {
  290.             printf("NO");
  291.         }
  292.         printf("\n");
  293.     }
  294.     return 0;
  295. }
  296. //TÁCH TỪ
  297. #include<stdio.h>
  298. #include<string.h>
  299.  
  300. int main()
  301. {
  302.     char s[100];
  303.     gets(s);
  304.     int dodai=strlen(s) - 1;
  305.     int i,j;
  306.     while(s[dodai]==' '){
  307.         dodai--;
  308.     }
  309.     for(i = 0;i<=dodai;i++){
  310.         if(s[i]==' '){
  311.             s[i]='\n';
  312.         }
  313.     }
  314.     printf("%s", s);
  315.     return 0;
  316. }
  317. //SỐ ĐẦY ĐỦ
  318. #include<stdio.h>
  319. #include<string.h>
  320. int CheckHopLe(char so[], int dodai){
  321.     int i,count=0;
  322.     for(i = 0; i < dodai; i++){
  323.         if(so[i]<48||so[i]>57){
  324.             count++;
  325.         }
  326.     }
  327.     if(count==0&&((int)so[0]-48)!=0){
  328.         return 1;
  329.     } else {
  330.         return 0;
  331.     }
  332. }
  333. int main(){
  334.     int t;
  335.     scanf("%d", &t);
  336.     while(t--){
  337.         char so[1000];
  338.         scanf("%s", so);
  339.         int dodai = strlen(so);
  340.         int check[10];
  341.         int i,check1=0;
  342.         for(i = 0; i < 10; i++){
  343.             check[i]=0;
  344.         }
  345.         if(CheckHopLe(so,dodai)==0){
  346.             printf("INVALID");
  347.         } else {
  348.             for(i = 0; i<dodai;i++){
  349.                 check[(int)so[i]-48]++;
  350.             }
  351.             for(i = 0; i<10; i++){
  352.                 if(check[i]==0){
  353.                     check1++;
  354.                 }
  355.             }
  356.             if(check1==0){
  357.                 printf("YES");
  358.             }else{
  359.                 printf("NO");
  360.             }
  361.         }
  362.         printf("\n");
  363.     }
  364.     return 0;
  365. }
  366. //SỐ ƯU THẾ
  367. #include<stdio.h>
  368. #include<string.h>
  369. int CheckHopLe(char so[], int dodai){
  370.     int i,count=0;
  371.     for(i = 0; i < dodai; i++){
  372.         if(so[i]<48||so[i]>57){
  373.             count++;
  374.         }
  375.     }
  376.     if(count==0&&((int)so[0]-48)!=0){
  377.         return 1;
  378.     } else {
  379.         return 0;
  380.     }
  381. }
  382. int main(){
  383.     int t;
  384.     scanf("%d", &t);
  385.     while(t--){
  386.         char so[1000];
  387.         scanf("%s", so);
  388.         int dodai = strlen(so);
  389.         int check[10];
  390.         int i,chan=0,le=0;
  391.         if(CheckHopLe(so,dodai)==0){
  392.             printf("INVALID");
  393.         } else {
  394.             for(i = 0; i<dodai; i++){
  395.                 if(((int)so[i]-48)%2==0){
  396.                     chan++;
  397.                 } else {
  398.                     le++;
  399.                 }
  400.             }
  401.             int check = 0;
  402.             if(dodai%2==0&&chan>le){
  403.                 check = 1;
  404.             }
  405.             if(dodai%2==1&&le>chan){
  406.                 check = 1;
  407.             }
  408.             if(check==1){
  409.                 printf("YES");
  410.             } else {
  411.                 printf("NO");
  412.             }
  413.            
  414.         }
  415.         printf("\n");
  416.     }
  417.     return 0;
  418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement