SHARE
TWEET

Untitled

a guest Oct 18th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. int main()
  5. {
  6.  int n, i, k, l, j;
  7.  char** name;
  8.  int* ch;
  9.  char** list;
  10.  int* reit;
  11.  int* sum;
  12.  char* str;
  13.  setlocale(LC_ALL, "Rus");
  14.  printf("Введите n\n");
  15.  scanf_s("%d",&n);
  16.  name = (char**)calloc(n, sizeof(char*));
  17.  str = (char*)calloc(15, sizeof(char));
  18.  ch = (int*)calloc(n, sizeof(int));
  19.  list = (char**)calloc(n, sizeof(char*));
  20.  reit = (int*)calloc(n, sizeof(int));
  21.  sum = (int*)calloc(n, sizeof(int));
  22.  printf("Введите информацию\n");
  23.  for (i = 0; i < n; i++)
  24.  {
  25.   printf("Введите название\n");
  26.   scanf_s("%s", str, 15);
  27.   name[i] = (char*)calloc(strlen(str) + 1, sizeof(char));
  28.   strcpy_s(name[i], strlen(str) + 1, str);
  29.   printf("Введите характеристику\n");
  30.   scanf_s("%d", &ch[i]);
  31.  }
  32.  k = 0;
  33.  for (i = 0; i < n; i++)
  34.  {
  35.   l = -1;
  36.   j = 0;
  37.   while (l == -1 && j < k)
  38.   {
  39.    if (strcmp(name[i], list[j]) == 0) { l = j; }
  40.    j++;
  41.   }
  42.   if (l == -1)
  43.   {
  44.    list[k] = (char*)calloc(strlen(name[i]) + 1, sizeof(char));
  45.    strcpy_s(list[k], strlen(name[i]) + 1, name[i]);
  46.    reit[k] = 1;
  47.    sum[k++] = ch[i];
  48.   }
  49.   else
  50.   {
  51.    reit[l]++;
  52.    sum[l] += ch[i];
  53.   }
  54.  }
  55.  printf("Список без повторений, рейтинга и характеристик\n");
  56.  for (i = 0; i < n; i++)
  57.  {
  58.   printf("%s %d %d\n", list[i], reit[i], sum[i]);
  59.  }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top