- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- int i = 0, j, k, a = 0, cmp, ansct[110][1010] = {{0},{0}}, hold, li = 0, index[1010], cmp2, cmp3;
- 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"};
- 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"};
- for(i = 0;i < 1010;i++){
- index[i] = i;
- }
- while(gets(g) != NULL){
- gets(g);
- token = strtok( g, " ,+-*/=()|&;{}[]!#\"<>");
- while(token != NULL){
- for(j = 0;j < 32;j++){
- cmp = strcmp(*(rword+j), token);
- if(cmp == 0)
- break;
- }
- if(cmp != 0){
- for(j = 0;j < 53;j++){
- cmp2 = strncmp(token, *(check+j), 1);
- }
- if(cmp2 == 0){
- for(k = 0;k < a;k++){
- cmp3 = strcmp(ans[k], token);
- if(cmp3 == 0){
- ansct[k][li] = 1;
- break;
- }
- }
- if(cmp3 != 0){
- strcpy(ans[a], token);
- ansct[a][li] = 1;
- }
- a++;
- }
- token = strtok(NULL," ,+-*/=()|&;{}[]!#\"<>");
- }
- }
- li++;
- }
- for(i = 0;i < a;i++){
- for(j = 0;j < a;j++){
- if(strcmp(ans[index[j]], ans[index[j + 1]]) > 0){
- hold = index[j];
- index[j] = index[j + 1];
- index[j + 1] = hold;
- }
- }
- }
- for(i = 0;i < a + 1;i++){
- printf("%s: ", ans[index[i]]);
- for(k = 0;k < 1010;k++){
- if(ansct[index[i]][k] == 1)
- printf("%d ", k + 1);
- }
- printf("\n");
- }
- system("pause");
- return 0;
- }
Raw Paste