Molly And Flame

QUESTION

Molly is in love with Sherlock .She wants to decide the nature of relationship between her and Sherlock using the game of FLAME.\n\nFLAME stands for: \n{\”Friendship\”,\”Love\”,\”Affection\”,\”Marriage\”,\”Enemies\”}\n\nThe rules of FLAME are:\n\n1) The names of two people are taken.\n\n2) Then the common letters are deleted from both the names.\n\n3) Then x_rem is calculated which is the number of leftover letters in both the names.\n\n4) Count through the letters of \”FLAME\” x_rem times. After you have counted the 5 letters of \”FLAME,\” you can continue counting from 6 to 10 starting again at \”F\” and ending at \”E,\” if needed. If you have more than 10 leftover letters, repeat the process a third time, starting with \”F.\”\n\n5) The letter at which you stop decides the nature of relationship.\n\nExample:\n\n1)consider the strings sherlock and molly.\n\n2)After striking off the common letters : sherck my\n\n3) x_rem = len(sherck) + len(my) = 8\n\n4) counting through the letters of FLAME.\n\nFLAME\n12345\n678\n\n5) The count stops at A . Hence the result is Affection.\n\nHowever , Molly is not happy with the result of the game(Affection) and she manipulates the string FLAME TO FALME to change the result of the game(Love).\n\nGiven two names perform minimum number of swaps on the string \”FLAME\” and print the new string so that nature of relationship is always Love.\n\nInput Format: \nFirst line containing number of testcases t. Next t lines contain two space separated names in lowercase. \nOutput Format: \nPrint the new string in a new line for each testcase.\n\nConstraints:\n1T100\n1lengthofname100000.

ANSWER

#include <stdio.h>
 
int main()
{
    int N;
    int flag=0;
    scanf("%d",&N);
    //printf(
    //"%d\n",N);
    while(N!=0)
    {
    char firstname[100000];
    char secondname[100000];
    scanf("%s",firstname);
    scanf("%s",secondname);
    int firstlength=0,secondlength=0,length=0;
    for(int i=0;firstname[i]!='\0';i++)
    {
        firstlength++;
        if(firstname[i]=='0')
        {
        continue;
        }
      
        
        for(int j=0;secondname[j]!='\0';j++)
        {
            if(i==0)
            secondlength++;
            
            
            if(firstname[i]==secondname[j])
            {
          //      printf("*%c*",secondname[j]);
                //firstname[i]='0';
                secondname[j]='0';
                length+=1;
                flag=1;
                
            }
        }
        
        
        
        if(flag)
        {
        length+=1;
        int k=i+1;
          for(;firstname[k]!='\0';k++)
        {
            
            if(firstname[i]==firstname[k])
            {
                firstname[k]='0';
                length+=1;
        
        //printf("no");
        }
        
            
        }
        //printf("HERE");
        
        }
    
        flag=0;
    }
    
   // printf("-%d-%d-",firstlength,secondlength);
  //  printf("%d",firstlength+secondlength-length);
    
    int x = ((firstlength+secondlength-length)%5);
    
    switch (x)
    {
    case 1:
    printf("LFAME\n");
    break;
    case 2:
    printf("FLAME\n");
    break;
    case 3:
    printf("FALME\n");
    break;
    case 4:
    printf("FMALE\n");
    break;
    case 0:
    printf("FEAML\n");
    break;
    }
    N--;
    }
    
    return 0;
}

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO