I tried all possible test cases and It outputed the correct answer , I wonder why UVA doesn't accept my answer
<#include<iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int i, j;
    unsigned long long int tempI, tempJ;
    int maxCaseLen = 1;
    int count = 1;
    while (scanf("%d %d", &i, &j) == 2)
    {
        if (i>j)
        {
            tempI = j;
            tempJ = i;
        }
        else
        {
            tempI = i;
            tempJ = j;
        }
        int iTemp = tempI;
        while (iTemp <= tempJ)
        {
            unsigned long long int n = iTemp;
            while (n != 1)
            {
                if (n % 2 == 1)
                {
                    n = 3 * n + 1;
                }
                else
                {
                    n = n / 2;
                }
                count++;
            }
            if (maxCaseLen < count)
            {
                maxCaseLen = count;
                count = 1;
            }

            else
                count = 1;
            iTemp++;
        }
        printf("%d %d %d", i, j, maxCaseLen);
    }
    return 0;
}

/>

Recommended Answers

All 5 Replies

wonder why UVA doesn't accept my answer

How are we supposed to know that? You didn't even tell us what that program is supposed to do. And what is UVA? My guess University of Virginia???

your answer for 201 210 is 174, should be 89 according to the example input/output in the instructions.

Your program appears to be retaining one of the last answers

1 10
1 10 20
100 200
100 200 125
201 210
201 210 125
900 1000
900 1000 174

The problem is that you need to reset maxCaseLen back to 1 after the scanf(), between lines 12 and 13.

Thank You Ancient Dragon :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.