void find_mix()
{
	int i, j, n;
	letters *l, *p;

	no_dup();
	n = n_states * (n_states - 1) / 2;
	p = l = calloc(n, sizeof(letters));

	for (i = 0; i < n_states; i++)
		for (j = i + 1; j < n_states; j++, p++) {
			count_letters(p, states[i]);
			count_letters(p, states[j]);
		}

	qsort(l, n, sizeof(letters), lcmp);

	for (j = 0; j < n; j++) {
		for (i = j + 1; i < n && !lcmp(l + j, l + i); i++) {
			if (l[j].name[0] == l[i].name[0]
				|| l[j].name[1] == l[i].name[0]
				|| l[j].name[1] == l[i].name[1])
				continue;
			printf("%s + %s => %s + %s\n",
				l[j].name[0], l[j].name[1], l[i].name[0], l[i].name[1]);
		}
	}
	free(l);
}
Exemple #2
0
/*******************************************************************************
*
* FUNCTION NAME: main
*
* DESCRIPTION: Accepts the source and trial string and calls the functions
*
* RETURNS: Returns 0
*******************************************************************************/
int main(int argc, char *argv[])
{
    char line[MAX_LINE_LENGTH];
    int target[MAX_ANAGRAM_LEN] = {0}, // Count of characters for target string
    trial[MAX_ANAGRAM_LEN]= {0};  // Count of characters in test string

    printf("Enter the target string:\n");

    get_line(line, sizeof(line)); // Read in target string
    count_letters(line, target); // Count the numbers for each string

    printf("Enter a test string (to exit just press ENTER key :\n");

    while (get_line(line, sizeof(line))) // Read in candidates for comparison
    {
        count_letters(line, trial); // Count the numbers for each letter

        if (anagram_checker(target, trial)) //Compare the letter frequencies
            printf("Result : It is an Anagram! \n");
        else
            printf("Result : Not an Anagram. Try again\n");

    }
    return 0;
}
Exemple #3
0
int main(void)
{
	int alphabet[27], alphcount, strcount, length;
	char *string;
    string = (char*) malloc(200);/*sets size of array to read user input into = 200 bytes*/

	printf("enter some words:\n");
	fgets(string, 200, stdin);
	length = strlen(string);
	
	for (alphcount = 0; alphcount < 26; alphcount++)/* for loop to set all count values in alphabet array to 0*/
	{
		alphabet[alphcount] = 0;
	}
	
	for (strcount = 0; strcount < length ; strcount++)/*for loop which calls 'count_letters function' for each character in the string entered by user*/
	{
		count_letters(string, alphabet, alphcount, strcount); /*call function*/
	}
		
	printf("The totals for each letter (both upper and lower case) are:\n");
	
	for (alphcount = 0; alphcount < 26; alphcount++) /*for loop to print out each letter of the alphabet and the total 
														count as calculated in count_letters function. 
														%c and "alphacount+97" call the alphabet character based on ASCII
														%d and alphabet[alphacount] calls the total for each alphabet character
													*/
	{
		printf("%c = %d\n", alphcount+97, alphabet[alphcount]);/*ASCII: 97 is "a", 98 is "b", etc. */
	}
		
	free(string);
	string = NULL;
	return 0;
}
	int main(int argc, char* argv[]){
		char line[MAX_LEN] = "Hello World!";
		
		int* letter_count = NULL;		
		letter_count = count_letters(line);
		
		print_letter_count(letter_count);
		
		return 0;
	}
Exemple #5
0
int count_pages(const char *string) {
  int num_newlines = count_letters(string, '\n', strlen(string));
  
  // if we just have one extra line, ignore the paging prompt and just send
  // the entire thing
  if(num_newlines <= NUM_LINES_PER_PAGE + 1)
    return 1;

  return ((num_newlines / NUM_LINES_PER_PAGE) + 
	  (num_newlines % NUM_LINES_PER_PAGE != 0));
}
Exemple #6
0
void part2(){
  char c;
  Vector in = Vector_create_char();
  long long count = 0;
  while(scanf("%c", &c) != EOF){
    Vector_push_char(in, c);
  }
  Vector_push_char(in, 0);
  count = count_letters(in, 0, -1);
  printf("%lld\n", count);
  Vector_free(in);
}
void do_string(const char *str)
{
	least_overlap = strlen(str);
	strcpy(orig, str);

	seq_no = 0;
	out[least_overlap] = '\0';
	least_overlap ++;

	permutate(count_letters(str), least_overlap - 2, 0);
	printf("%s -> %s, overlap %d\n", str, best, least_overlap);
}
int main(int c, char **v)
{
	int i, j = 0;
	char *words;
	struct stat st;

	int fd = open(c < 2 ? "unixdict.txt" : v[1], O_RDONLY);
	if (fstat(fd, &st) < 0) return 1;

	words = malloc(st.st_size);
	read(fd, words, st.st_size);
	close(fd);

	union node root = {{0}};
	unsigned char cnt[26];
	int best_len = 0;
	const char *b1, *b2;

	for (i = 0; freq[i]; i++)
		char_to_idx[(unsigned char)freq[i]] = i;

	/* count words, change newline to null */
	for (i = j = 0; i < st.st_size; i++) {
		if (words[i] != '\n') continue;
		words[i] = '\0';

		if (i - j > best_len) {
			count_letters(words + j, cnt);
			const char *match = insert(&root, words + j, cnt);

			if (match) {
				best_len = i - j;
				b1 = words + j;
				b2 = match;
			}
		}

		j = ++i;
	}

	if (best_len) printf("longest derangement: %s %s\n", b1, b2);

	return 0;
}
Exemple #9
0
int rdp(Vector in, int pos, long long *length, int recurse){
  if(Vector_data_char(in)[pos] == '('){
    int cur_pos = pos;
    int num_letters;
    int repeat;
    char c;
    if (sscanf(&Vector_data_char(in)[pos+1], "%dx%d%c", &num_letters, &repeat, &c) == 3 && c == ')'){
      while(Vector_data_char(in)[cur_pos++] != ')');
      if(recurse){
        *length = count_letters(in, cur_pos, cur_pos + num_letters) * repeat;
      }
      else{
        *length = num_letters * repeat;
      }
      return cur_pos+num_letters;
    }
  }
  if(Vector_data_char(in)[pos] != ' ' && Vector_data_char(in)[pos] != '\n') *length = 1;
  else *length = 0;
  return pos+1;
}
Exemple #10
0
/*************************************************************
 * Learns XUniversity's encoding system from given files ,   *
 * decodes their encoded messages and writes as plain text to*
 * a file                                                    *
 *************************************************************/
int
main()
{
    FILE *f_character_list_ptr, *f_sample_file_ptr, *f_encoded_ptr,
         *f_plain_text_ptr;
    int character_number;
    char c1, c2, c3;

    f_character_list_ptr=fopen(CHARACTERFILE, "r");

    /* exit program and print error if character list file could not be opened to read */
    if(f_character_list_ptr==NULL) {
        printf("Error!File could not opened to read.");
        return 1;
    }

    /* call read_character_list function and get return value *
     * if number of letter read is not equal to three exit    *
     * program                                                */
    character_number=read_character_list(f_character_list_ptr, &c1, &c2, &c3);
    if(character_number!=3) {
        printf("Character number is not equal to 3.");
        return 1;
    }

    /* close character list file */
    fclose(f_character_list_ptr);

    f_sample_file_ptr=fopen(SAMPLEFILE, "r");

    /* exit program and print error if sample file could not be opened to read */
    if(f_sample_file_ptr==NULL) {
        printf("Error!File could not opened to read.");
        return 1;
    }

    /* Call count_letters function and swap letters inside function *
     * according to number of counts                                */
    count_letters(f_sample_file_ptr, &c1, &c2, &c3);

    /* close sample file */
    fclose(f_sample_file_ptr);

    /*open encoded and plain text file*/
    f_encoded_ptr=fopen(ENCODEDFILE, "r");
    f_plain_text_ptr=fopen(PLAINTEXTFILE, "w");

    /* exit program and print error if encoded file could not be opened to read */
    if(f_encoded_ptr==NULL) {
        printf("Error!File could not opened to read.");
        return 1;
    }

    /* exit program and print error if plain text file could not be opened to write */
    if(f_plain_text_ptr==NULL) {
        printf("Error!File could not opened to write.");
        return 1;
    }

    /* Call decode function */
    decode(f_encoded_ptr,f_plain_text_ptr,c1,c2,c3);

    /* close encoded and plain text file */
    fclose(f_encoded_ptr);
    fclose(f_plain_text_ptr);

    return 0;
}