C   25
ansct index
Guest on 20th September 2023 12:07:38 AM


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.         int i = 0, j, k, a = 0, cmp, ansct[110][1010] = {{0},{0}}, hold, li = 0, index[1010], cmp2, cmp3;
  8.         char g[2000], *token, ans[110][2000], *temp, *rword[32] = {"auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while"};
  9.         char check[][2] = {"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", "_", "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"};
  10.         for(i = 0;i < 1010;i++){
  11.             index[i] = i;
  12.     }
  13.         while(gets(g) != NULL){
  14.             gets(g);
  15.             token = strtok( g, " ,+-*/=()|&;{}[]!#\"<>");
  16.             while(token != NULL){
  17.                     for(j = 0;j < 32;j++){
  18.                             cmp = strcmp(*(rword+j), token);
  19.                             if(cmp == 0)
  20.                                 break;
  21.                     }
  22.                     if(cmp != 0){
  23.                             for(j = 0;j < 53;j++){
  24.                                     cmp2 = strncmp(token, *(check+j), 1);
  25.                     }
  26.                     if(cmp2 == 0){
  27.                                         for(k = 0;k < a;k++){
  28.                                             cmp3 = strcmp(ans[k], token);
  29.                                                 if(cmp3 == 0){
  30.                                                     ansct[k][li] = 1;
  31.                                                     break;
  32.                                                 }
  33.                                         }
  34.                                         if(cmp3 != 0){
  35.                                 strcpy(ans[a], token);
  36.                                     ansct[a][li] = 1;
  37.                                         }
  38.                                 a++;
  39.                                 }
  40.                         token = strtok(NULL," ,+-*/=()|&;{}[]!#\"<>");
  41.                         }
  42.                 }
  43.                 li++;
  44.     }
  45.     for(i = 0;i < a;i++){
  46.             for(j = 0;j < a;j++){
  47.                     if(strcmp(ans[index[j]], ans[index[j + 1]]) > 0){
  48.                             hold = index[j];
  49.                             index[j] = index[j + 1];
  50.                             index[j + 1] = hold;
  51.                         }
  52.                 }
  53.         }
  54.         for(i = 0;i < a + 1;i++){
  55.                 printf("%s: ", ans[index[i]]);
  56.                 for(k = 0;k < 1010;k++){
  57.                 if(ansct[index[i]][k] == 1)
  58.                     printf("%d ", k + 1);
  59.                 }
  60.                 printf("\n");
  61.     }
  62.     system("pause");
  63.         return 0;
  64. }

Raw Paste

Login or Register to edit or fork this paste. It's free.