Burrows and Scofield

Michael Scofield and Lincoln Burrows are working on a secret mission. Michael is needed to give a se…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

Why Wrong Answer 5?

// Burrows and Scofield
//
// Created by Abuhena Rony

#include <bits/stdc++.h>

int secret_number(char w1[], char w2[])
{
    int sum1, sum2, addnum, mulnum, subnum, middle_number;
    sum1 = 0;
    for (size_t i = 0; i < strlen(w1); ++i)
    {
        for (size_t j = 0; j < 10; ++j)
        {
            if (w1[i] - '0' == j)
                sum1 = sum1 + j;
        }
    }
    sum2 = 0;
    for (int i = 0; i < strlen(w2); ++i)
    {
        for (int j = 0; j < 10; ++j)
        {
            if (w2[i] - '0' == j)
                sum2 = sum2 + j;
        }
    }
    addnum = sum1 + sum2;
    mulnum = sum1 * sum2;
    subnum = sum1 - sum2;
    // printf("Sum1 = %d, Sum2 = %d\n", sum1, sum2);
    if (subnum < 0)
        subnum = (-1) * subnum;
    // printf("AddNum = %d, MulNum = %d, SubNum = %d\n", addnum, mulnum, subnum);
    if ((addnum < mulnum && addnum > subnum) || (addnum < subnum && addnum > mulnum))
        middle_number = addnum;
    if ((mulnum > addnum && mulnum < subnum) || (mulnum < addnum && mulnum > subnum))
        middle_number = mulnum;
    if ((subnum < addnum && subnum > mulnum) || (subnum > addnum && subnum < mulnum))
        middle_number = subnum;
    // printf("Middle Number = %d\n", middle_number);
    return middle_number;
}

int main()
{
    char word1[10000];
    char word2[10000];
    scanf("%s", word1);
    scanf("%s", word2);
    // printf("First Word: %s\nSecond Word: %s\n", word1, word2);
    printf("\"%d\"", secret_number(word1, word2));
    printf("\n");
    return 0;
}