c permutation and combination with frequency

This is a discussion on c permutation and combination with frequency within the C Programming forums, part of the General Programming Boards category; I have 2 strings where I have saved fixed 20 characters and these are “A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T” and same 20 char in ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    1

    c permutation and combination with frequency

    I have 2 strings where I have saved fixed 20 characters and these are “A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T” and same 20 char in string 2. so I will get 400 combinations of 2 character sets like
    AA,AB,AC,AD,AE,AF,……………AT
    BA,BB,BC,BD,BE,BF,…………..BT
    CA,CB,CC,CD,CE,CF……………CT

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    
    
    
    int main()
    {
    	int count = 0;
    	char sequence1[30] = "ACDEFGHILPNQYWRKMTSV";
    	char sequence2[30] = "ACDEFGHILPNQYWRKMTSV";
    	const char sequence3[30] = "AAGACDF";	/*sequence taken from user which will be of length 31*/
    	printf(" %s %s \n ",sequence1,sequence2);
    	for (int i=0; i<strlen(sequence1); i++)
    	{
    		for(int j=0;j<strlen(sequence2);j++)
    		{
    		      printf(" %c %c",sequence1[i],sequence2[j]);
    			for(int k=0; k < strlen(sequence3)-1; k++)
    			{
    				if(sequence3[k] == sequence1[i] && sequence3[k+1] == sequence2[j])
    				{
    					//cout<<"(equal)\t";
    					count++;
    				}
    			}
    		}
    	}
    
    	printf("the number of matches are found %d ",count);
    	getch();
    
    }

    This way we will get 400 combinations (Which program I have created successfully) but then user will put the value till 31 characters witch will be treated as 3rd string for E.g. “ABCDDAAAB” now I have to check the frequency of user input in the sequence of 12,23,34,45,56,67,78,89 (2 CHAR SET) means AB,BC,CD,DD,DA,AA,AA,AB and need to show the frequency
    of user input

    OUTPUT:

    AB=2
    BC=1
    CD=1
    DD=1
    DA=1
    AA=2

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Add the two char's, and use that to counting sort them. Looks like you'll need a different row or array, for each primary (leftmost) letter, to avoid collisions:

    input: A+B , so (using separate arrays), arrayA[A+B]++;
    or via rows, Array[A][A+B]++;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Permutation?
    By koolguysj in forum C Programming
    Replies: 1
    Last Post: 04-02-2005, 09:24 AM
  2. Permutation Calculation
    By Eric Hansen in forum C++ Programming
    Replies: 21
    Last Post: 06-11-2003, 05:03 PM
  3. Permutation and Combination
    By vasanth in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2002, 10:53 AM
  4. permutation
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 09-01-2001, 05:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21