English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類
0

題目 :
The Input
The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0.

You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.


The Output
For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).

Sample Input

1 10
100 200
201 210
900 1000


Sample Output

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

我的測試結果 :
1 10
1 10 20
100 200
100 200 125
201 210
201 210 125//這行為什麼不對???
900 1000
900 1000 174

code :

#include
#include

int main(void)
{
int a, b, i, j, x, y, sum, max=0;

while(1)
{
scanf("%d %d",&i,&j);

if (i > 0 && j < 10000 && i < j)
{
x = i;
y = j;
}

else if (i > 0 && j < 10000 && i > j)
{
x = j;
y = i;
}


do
{
b = x;
sum = 1;

do
{
if(b % 2 == 1)
a = 3 * b 1;

else
a = b / 2;

sum = sum 1;

b = a;

}while(a != 1);

x = x 1;

if(sum > max)
max = sum;

else
max = max;

}while(x < y);

printf("%d %d %d\n", i, j, max);/*輸出最大數列*/
}

system("PAUSE");
return 0;
}

2007-02-22 18:33:39 · 1 個解答 · 發問者 2 in 電腦與網際網路 程式設計

如果不連續測試就會對了˙˙why????

2007-02-22 18:34:16 · update #1

1 個解答

因為你的 max 沒有歸 0, 加上這行就可以了

max = 0;
do
{
b = x;
sum = 1;
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2007-02-22 20:54:00 · answer #1 · answered by JJ 7 · 0 0

fedest.com, questions and answers