Friday, 24 July 2015

BANDW

Standard

Black and White

Link to the question : BANDW 

HINT :

My solution is very basic.Let the input string be s[] and the objestive string be t[].  Run a loop till the end. If s[i] = t[i] continue, else if they are not equal, keep a count again when they are equal.
I think checking the source code once will make it more clear.

RECOMMENDED QUESTION :

Try this adhoc question after this one.

SOURCE CODE :

/* Black And White */
/* Sushant Gupta */

#include<stdio.h>
#include<string.h>
int main()
{
    char s[600],t[600];
    int i;
    s[0]= '0';

    while(s[0]!= '*')
    {
        scanf("%s%s",s,t);
        if(s[0]!= '*')
        {
            int n,c=0;
            n = strlen(s);
            i=0;
            while(i<n)
            {
                if(s[i]!=t[i]) {
                while(s[i]!=t[i])
                    i++;
                c++;}
                while(s[i]==t[i])
                    i++;
            }
            printf("%d\n",c);
        }
        else
            return 0;
    }
}
 

0 comments:

Post a Comment