Advertisement
Hanaigi

Untitled

Nov 23rd, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. 1)
  2. #include <stdio.h>
  3. #include <string.h>
  4. int main()
  5. {
  6.     char s[80], p[4] = "app";
  7.     char* token;
  8.     fgets(s, 50, stdin);
  9.     token = strtok(s, ",");
  10.     while (token != NULL)
  11.     {
  12.         if (strncmp(token, p, 3) == 0)
  13.             printf("%s\n", token);
  14.         token = strtok(NULL, ",");
  15.     }
  16. }
  17. ------------------------------------------
  18. 2)
  19. #include "string.h"
  20. #include "istream"
  21. int main () {
  22.     char s[1000], p[10];
  23.     int c = 0;
  24.     fgets(s, 1000, stdin);
  25.     fgets(p, 10, stdin);
  26.     char *sl = strtok(s," ");
  27.     int h = strlen(p) - 1;
  28.     while (sl != NULL){
  29.         if (strncmp(sl, p, h) == 0){
  30.             c++;
  31.         }
  32.         sl = strtok(NULL," ");
  33.     }
  34.     printf("%d", c);
  35. }
  36. ------------------------------------------------
  37. 3)
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <istream>
  41. int srt(const void* a, const void* b) {
  42.     char** surnameA = (char**)a;
  43.     char** surnameB = (char**)b;
  44.     return strcmp(*surnameA, *surnameB);
  45. }
  46. int main() {
  47.     char name[100];
  48.     char* name1[20];
  49.     int c = 0;
  50.     fgets(name, 100, stdin);
  51.     char* tok = strtok(name, ", ");
  52.     while (tok != NULL) {
  53.         name1[c] = strdup(tok);
  54.         c=c+1;
  55.         tok = strtok(NULL, ", ");
  56.     }
  57.     qsort(name1, c, sizeof(char*), srt);
  58.     printf("sort:\n");
  59.     for (int i = 0; i < c; i++) {
  60.         printf("%s\n", name1[i]);
  61.         free(name1[i]);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement