UVA(3n + 1问题)输出错误的答案 [英] UVA (3n+1 Problem) outputs wrong answer

查看:70
本文介绍了UVA(3n + 1问题)输出错误的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个UVa 3n + 1我仍然是解决问题的初学者,我尝试了所有案例并检查他们输出了正确答案但我想知道为什么UVa输出错误答案我提交的代码我检查了互联网棘手的测试用例,并尝试了人们建议的所有测试用例,输出是正确的,所以为什么UVa说输出是错误的?!!!!任何帮助将不胜感激

问题陈述

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36 [ ^ ]

This is a UVa 3n+1 I'm still a beginner in problem solving and I tried all cases and checked that they output the correct answer but I wonder why the UVa ouputs Wrong answer to my submitted code I checked the internet for tricky test cases and tried all the test cases that people suggested and the output was correct as expected so why the UVa says that the output is wrong ?!!!! any help would be appreciated
The Problem Statement
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36[^]

#include<iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int i, j;
	
	
	while (scanf("%d %d", &i, &j) == 2)
	{
		unsigned long long int tempI, tempJ;
		int maxCaseLen = 1;
		int count = 1;
		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;
}

推荐答案

这篇关于UVA(3n + 1问题)输出错误的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆