예제 #1
0
파일: node.cpp 프로젝트: azelick/cs202p1-2
void Node::find_words(Dict_Word *&head, Node * root, const char letter)
{
   if(!root)
   {
       return;
   }
   
   //check each letter in word to see if it matches
   int size = strlen(root->word);
   for(int i = 0; i < size; ++i)
   {
       if(root->word[i] == letter)
       {
           if(!head)
           {
               //add to LLL
               head = new Dict_Word();
               head->word = new char[strlen(root->word) + 1];
               strcpy(head->word, root->word);
               head -> next = NULL;
           }
           else
           {
               Dict_Word * temp = new Dict_Word();
               temp->word = new char[strlen(root->word) + 1];
               strcpy(temp->word, root->word);
               temp-> next = head;
               head = temp;
           }
       }
   }
   find_words(head, root->left, letter);
   find_words(head, root->right, letter);
}
예제 #2
0
OutputIterator xref(std::istream& in,
		    void find_words(const std::string&, std::back_insert_iterator<std::vector<std::string> >),
		    OutputIterator d) {
  std::string line;
  int line_number = 0;
  std::map<std::string, std::vector<int> > ret;
  
  // read the next line
  while (getline(in, line)) {
    ++line_number;

    // break the input line into words
    std::vector<std::string> words;
    find_words(line, back_inserter(words));

    // remember that each word occurs on the current line
    for (std::vector<std::string>::const_iterator it = words.begin();
	 it != words.end(); ++it)
      ret[*it].push_back(line_number);
  }

  // write results to output iterator
  copy(ret.begin(), ret.end(), d);

  return d;
}
예제 #3
0
int main()
{
	int x;
	char a[20];
	WORD_NODE *root;
	root = creat();
	for(;;){	
		printf("input the value for fun()\n1: add\n2: del\n3: find\n");
		scanf("%d", &x);
		getchar();
		if(x == 1)
			add_words(root);
		if(x == 2){
			printf("please input the word:\n");
			gets(a);
			del_words(root, a);
		}
		if(x == 3){
			printf("please input the word:\n");
			gets(a);
			if(find_words(root, a))
				printf("exist\n");
			else printf("NONE\n");
		}
	}
	return 0;

}
예제 #4
0
파일: ft_spy.c 프로젝트: leandro518/42us
int		main(int argc, char **argv)
{
	char	temp[10000];
	int		i;
	int		j;
	int		k;

	i = 0;
	while (++i < argc)
	{
		j = 0;
		k = 0;
		while (argv[i][j])
		{
			if (argv[i][j] != ' ')
			{
				temp[k] = argv[i][j];
				k++;
			}
			j++;
		}
		temp[k] = '\0';
		to_lower(temp);
		if (find_words(temp) == 1)
			return (0);
	}
	return (0);
}
int main (int argc, char *argv[])
{
    FILE *fpi;
    long pos;
    char *trie = NULL;
    int  version, features;

    static unsigned char buffer[1024];

    for (;;) {
        int option_index = 0;
        int c;
        static struct option long_options[] = {
            {"trie", required_argument, 0, 't'},
            {0, 0, 0, 0}
        };

        c = getopt_long(argc, argv, "t:",
                        long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
        case 't':
            trie = optarg;
            break;
        default:
            printf("?? getopt returned character code 0%o ??\n", c);
        }
    }

    if (optind < argc) error (argv[0], "Excess argument");

    if (trie == NULL)  error (argv[0], "Missing argument --trie");

    fpi = fopen (trie, "r");
    if (fpi == NULL) {
        fprintf (stderr, "Unable to open file \"%s\"\n", trie);
        return 1;
    }

    {
        char *buf = malloc (4096);
        setbuffer (fpi, buf, 4096);
    }

    pos = trie_hdr_read (fpi, &version, &features);

    find_words (fpi, features, pos, buffer, buffer);

    return 0;
}
예제 #6
0
파일: xref_os.cpp 프로젝트: joharrow/acpp
std::ostream& xref(std::istream& in, std::ostream& out, void find_words(const std::string&, std::back_insert_iterator<std::vector<std::string>>))
{
    std::string line;
    int line_number = 0;
    std::map<std::string, std::vector<int>> ret;
    while(std::getline(in, line)) {
	++line_number;
        std::vector<std::string> words;
	find_words(line, std::back_inserter(words));
        for(std::vector<std::string>::const_iterator it = words.begin(); it != words.end(); it++)
	    if(std::find(ret[*it].begin(), ret[*it].end(), line_number) == ret[*it].end())
	        ret[*it].push_back(line_number);
    }
    std::copy(ret.begin(), ret.end(), out);
    return out;
}
예제 #7
0
map<string, vector<int> > xref(instream& in,
		vector<string> find_words(const string&) = split)
{
	string line;
	int line_number = 0;
	map<string, vector<int> > ret;

	while(getline(in, line)){
		++line_number;

		vector<string> words = find_words(line);

		for (vector<string>::const_iterator it = words.begin();
				it != word.end(); ++it)
			ret[*it].push_back(line_number);
	}
	return ret;
}
int main()
{
    std::vector<std::vector<char>> board = {
        {'o','a','a','n'},
        {'e','t','a','e'},
        {'i','h','k','r'},
        {'i','f','l','v'}
    };

    std::vector<std::string> dictionary = {
        "oath","pea","eat","rain"
    };

    std::vector<std::string> result = find_words(board, dictionary);
    std::cout << "Board:" << std::endl;
    print_board(board);
    std::cout << "Dictionary:" << std::endl;
    print_vector(dictionary);
    std::cout << "Result:" << std::endl;
    print_vector(result);
    return 0;
}
예제 #9
0
void find_row_words(const char *line,	/* current contents */
		    const char *prev,	/* previous line */
		    const char *next,	/* next line */
		    Map allow[])	/* what characters are allowed */
{
  int col, lastim, numsp, lastex;
  static int content[15];

  encode_row(line, prev, next, allow, content);

  for (len=3; len<=15; len++) {
    lastim = -1;			/* last unplayable square */
    lastex = -1;			/* last existing tile */
    numsp = 0;				/* number of spaces */
    for (col=0; col<15; col++) {
      int c = content[col];
      if (c & SPACE) numsp++;		/* moved onto new space */
      if (col-len >= 0 && line[col-len] == EMPTY) numsp--;
      if (c & ADJOIN) lastex = col;
      if (c & NOPLAY) {
        lastim = col;
      }else{
        if (lastim <= col-len &&	/* 'len' letters allowed */
	    lastex > col-len &&		/* adjoins or includes existing tile */
	    (col==len-1 || line[col-len] == EMPTY) &&
	    (col==15-1 || line[col+1] == EMPTY) &&	/* bounded by spaces */
	    numsp > 0 &&		/* use at least 1 tile */
	    numsp <= num_tile) {	/* enough tiles */
	  play.col = col-len+1;
	  play_bonus = (numsp==7)? 50: 0; /* use all 7 tiles? */
	  find_words();
        }
      }
    }
  }
}
void find_words (FILE *fpi, int features, uint64_t pos, unsigned char *buffer, unsigned char *bp)
{
    int           len, end;
    unsigned char *cp;
    uint64_t      refpos, son, cnt;

    if (!pos) return;

    refpos = pos;

    for (;;) {
        trie_node_read (fpi, features, &refpos, &pos, &cnt, &len, &end, &son, bp);
        if (!len) break;

        cp = (unsigned char *) memchr (bp, '\t', len);

        if (cp != NULL) {
            fwrite (buffer, cp - buffer, 1, stdout);
            fputc ('\n', stdout);
        } else {
            find_words (fpi, features, son, buffer, bp + len);
        }
    }
}
예제 #11
0
wordnumber_t step_4_find_outliers(struct Parameters *pParam)
{
  FILE *pOutliers;
  FILE *pFile;
  struct InputFile *pFilePtr;
  char logStr[MAXLOGMSGLEN];
  char line[MAXLINELEN];
  char key[MAXKEYLEN];
  char words[MAXWORDS][MAXWORDLEN];
  int len, wordcount, i;
  struct Elem *pWord, *pElem;
  wordnumber_t outlierNum;
  
  outlierNum = 0;
  
  if (!(pOutliers = fopen(pParam->pOutlier, "w")))
  {
    sprintf(logStr, "Can't open outliers file %s", pParam->pOutlier);
    log_msg(logStr, LOG_ERR, pParam);
    exit(1);
  }
  
  for (pFilePtr = pParam->pInputFiles; pFilePtr; pFilePtr = pFilePtr->pNext)
  {
    if (!(pFile = fopen(pFilePtr->pName, "r")))
    {
      sprintf(logStr, "Can't open input file %s", pFilePtr->pName);
      log_msg(logStr, LOG_ERR, pParam);
      continue;
    }
    
    while (fgets(line, MAXLINELEN, pFile))
    {
      len = (int) strlen(line);
      if (line[len - 1] == '\n')
      {
        line[len - 1] = 0;
      }
      
      wordcount = find_words(line, words, pParam);
      
      *key = 0;
      
      for (i = 0; i < wordcount; i++)
      {
        pWord = find_elem(words[i], pParam->ppWordTable,
                  pParam->wordTableSize, pParam->wordTableSeed);
        if (words[i][0] != 0 && pWord)
        {
          strcat(key, words[i]);
          len = (int) strlen(key);
          key[len] = CLUSTERSEP;
          key[len + 1] = 0;
        }
      }
      
      if (*key == 0 && wordcount)
      {
        fprintf(pOutliers, "%s\n", line);
        outlierNum++;
        continue;
      }
      
      pElem = find_elem(key, pParam->ppClusterTable, pParam->clusterTableSize,
                pParam->clusterTableSeed);
      
      if (!pElem || (pElem->count < pParam->support))
      {
        fprintf(pOutliers, "%s\n", line);
        outlierNum++;
      }
    }
  }
  
  return outlierNum;
}
예제 #12
0
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    char input[256];
    for (;;)
    {
        gets(input);
        if (input[0] == '#') break;

        if (input[0]== 'P')
        {
            bool scanning_word = false;

            profile & px = p[pc++];
            px.threshold = atoi(input+3);
            px.wordnum   = 0;

            for (int i = 3, j = 0; input[i] != 0; i++)
            {
                char & c = input[i];
                if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
                {
                    if (!scanning_word)
                        px.words[px.wordnum ++] = px.data+j;
                    scanning_word = true;
                    px.data[j++] = c | 0x20;
                }
                else
                {
                    if (scanning_word)
                    {
                        px.data[j++] = '\0';
                        scanning_word = false;
                    }
                }
            }

            /*printf("P ----\n");
            for (int i = 0; i < px.wordnum; i++)
                printf("%d %s\n", i, px.words[i]);*/

        }
        else if (input[0]== 'T')
        {
            bool done = false;
            bool scanning_word = false;

            title & tx = t[tc++];
            tx.wordnum = 0;

            for (int j = 0;;)
            {
                for (int i = 3; input[i] != 0; i++)
                {
                    char & c = input[i];
                    if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
                    {
                        if (!scanning_word)
                            tx.words[tx.wordnum ++] = tx.data+j;
                        scanning_word = true;
                        tx.data[j++] = c | 0x20;
                    }
                    else if (c == '|')
                    {
                        tx.data[j] = '\0';
                        done = true;
                        break;
                    }
                    else if (('0' <= c && c <= '9') ||
                             c == '\'' || c =='(' || c == ')' || c == '-')
                    {}
                    else
                    {
                        if (scanning_word)
                        {
                            tx.data[j++] = '\0';
                            scanning_word = false;
                        }
                    }
                }

                if(done) break;
                tx.data[j++] = '\0';
                gets(input);
            }

            /*printf("T ----\n");
            for (int i = 0; i < tx.wordnum; i++)
                printf("%d %s\n", i, tx.words[i]);*/

        }
    }

    for (int i = 0; i < pc; i++)
    {
        profile & px = p[i];
        int mcount = 0;
        bool found;

        printf("%d: ", i+1);
        for (int j = 0; j < tc; j++)
        {
            title & tx = t[j];
            int curr, curr_index;
            int last = find_words(tx, px, 0, -1, curr_index);
            found = false;
            while (last != -1)
            {
                curr = find_words(tx, px, last+1, curr_index, curr_index);

                if (curr == -1)
                {
                    found = false;
                    break;
                }
                else if ((curr - last - 1) <= px.threshold)
                {
                    //fprintf(stderr, "found %d-%d\n", last, curr);
                    found = true;
                    break;
                }

                last = curr;
            }

            if (found)
            {
                if (mcount != 0) printf(",");
                printf("%d", j+1);
                mcount ++;
            }
        }
        printf("\n");
    }


#ifndef ONLINE_JUDGE
    //system("pause");
#endif
    return 0;
}