c permutation and combination with frequency

Discussion in 'C' started by oswalvishal, Apr 26, 2010.

  1. oswalvishal

    oswalvishal New Member

    Joined:
    Apr 25, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
    Code:
      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
     
    Last edited by a moderator: Apr 27, 2010
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You had the same thread twice and also the same post in the same thread twice.

    Avoid doing that.
     
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    1:
    2:
    How are the two (1 and 2) linked ??
    The problem that you mentioned in 2 can be solved independently !
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice