Friday, 1 December 2017

Code Challenge Solutions 5

1.  The FizzBizz Problem


Write a program to print numbers upto n.
With a catch that, if the number is a multiple of 3 print FIZZ
print BIZZ if multiple of 5
and FIZZBIZZ if it is both multiple of 3 and 5.


Program:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,j,k;
    int arr[100];
scanf("%d",&n);
    for(i=0;i<n;i++)
{
arr[i]=i;
}

for(i=1;i<n;i++)
        {
            if((arr[i]%5==0) && (arr[i]%3==0))
            printf("FizzBizz\n");
            else if(arr[i]%5==0)
            printf("Bizz\n");
            else if(arr[i]%3==0)
            printf("Fizz\n");
            else
            printf("%d\n",arr[i]);
        }

    if((n%5==0) && (n%3==0))
            printf("FizzBizz\n");
            else if(n%5==0)
            printf("Bizz\n");
            else if(n%3==0)
            printf("Fizz\n");
            else
            printf("%d\n",n);
    return 0;

}



2. Given two strings,

That may or may not be of the same length, determine the minimum number of character deletions required to make  and  anagrams. Any characters can be deleted from either of the strings.


Program:



#include<bits/stdc++.h>

using namespace std;

int main() {
    string str1,str2;
    getline(cin,str1);
    getline(cin,str2);

    int A[26],B[26],i;
    for(i=0 ; i< 26 ; i++)
        A[i] = B[i] = 0;
    for(i = 0 ; i< str1.length() ; i++)
        A[(int)(str1[i] - 'a')]++;
    for(i = 0 ; i< str2.length() ; i++)
        B[(int)(str2[i] - 'a')]++;
    int outp = 0;
    for(i=0 ; i< 26 ; i++)
    {
        outp = outp + A[i] + B[i] - 2*min(A[i],B[i]);
    }
    cout<<outp<<endl;
    return 0;

}