样例过了(有交换)但WA
查看原帖
样例过了(有交换)但WA
447562
像素旋转楼主2021/1/23 15:30
#include<iostream>
#include<cstdio>
void swap0(int&,int&);
int main(void)
{
	using namespace std;
	int n,n2,end;
	while (scanf("%d",&n) != EOF) {
		cin >> end;
		if (end < n)
			swap0(end, n);
		n2 = n;
		int max = 0;
		for (; n <= end; n++) {
			int n3 = n;
			int count = 0;
			while (n > 1) {
				if (n % 2 == 0)
					n /= 2;
				else n = 3 * n + 1;
				count++;
			}
			count++;
			if (max < count)
				max = count;
			n = n3;
		}
		cout << n2 << " " << end << " "
			<< max << endl;
	}
	return 0;
}
void swap0(int& a, int& b) {
	int t;
	t = a;
	a = b;
	b = t;
	return;
}
2021/1/23 15:30
加载中...