Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大佬们求助啊啊啊啊啊,小子不才,被水题撂倒

Posted by 1823200137 at 2019-03-03 14:24:42 on Problem 1207
#include <stdio.h>
int main(int argc, char const *argv[])
{
	int a, b, num;
	int max = 0;
	int temp;
	int flag = 0;

	while (scanf("%d%d", &a, &b) != EOF) {
		if (a > b) {
			temp = a;
			a = b;
			b = temp;
			flag = 1;
		}
		max = 0;

		for (int i = a; i < b + 1; ++i)
		{
			num = 1;
			if (a == 1 && b == 1)
			{
				max = 2;
			}

			for (int j = i; j != 1; )
			{

				if (j % 2 == 1) {
					j = 3 * j + 1;
				} else if (j % 2 == 0) {
					j = j / 2;
				}
				++num;

				if (num > max)
					max = num;
			}
		}

		if (flag == 0)
		{
			printf("%d %d %d\n", a, b, max);
		} else {
			printf("%d %d %d\n", b, a, max);

		}
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator