[Login|Register]
New post

Show post

Search forum

Read topic
What is wrong with it? 2010-05-12 11:32:59 qiren_chen
#include<stdio.h>

int i = 1;
int j = 1;
int f(int n)
{
    i = j;
    if(n==1)
        return 1;
    if(n%2==0)
    {
        n = n/2;
        j++;
        f(n);
    }
    else
    {
        n = n*3 + 1;
        j++;
        f(n);
    }
    j = 1;
    return i;
}


int main()
{
    int a, b, c;
    while(scanf("%d %d", &a, &b) != EOF)
    {
        int temp = 0;
        if(a > b)
        {
            temp = a;
            a = b;
            b = temp;
        }
        int index = 1;
        for(c=a; c<=b; c++)
        {                
            if(f(index) < f(c))
            {
                index  = c;
            }
        }
        if(temp != 0)
        {        
            printf("%d %d %d ",b, a, f(index));
        }
        else
        {
            printf("%d %d %d", a, b, f(index));
        }

        printf("\n");
    }
    return 0;
}
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.6ms with 1 query(s).