jyyeth


私信TA

用户名:jyyeth

访问量:34462

签 名:

C++学的完吗?

等  级
排  名 180
经  验 6679
参赛次数 0
文章发表 47
年  龄 0
在职情况 学生
学  校 徐州工程学院
专  业

  自我简介:

参考代码:

#include <iostream>
using namespace std;
int main()
{
    int i,j,tot;
    while(cin>>i>>j){
        cout<<i<<" "<<j<<" ";
        int maxt=0;
        if(i>j){int temp=i;i=j;j=temp;}
        for(int k=i;k<=j;k++){
            tot=1;
            int n=k;
            while(n!=1){
                if(n%2==0)n=n/2;
                else n=3*n+1;
                tot++;
            }
            if(maxt<tot) maxt=tot;
        }
        cout<<maxt<<endl;
    }
    return 0;
}



 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

#include<iostream>
using namespace std;
length(int x,int y)
{
	int i=0;
	int j;
	int sum;
	int str=0;
	for(j=x;j<y;j++)
	{
		sum=j;
		while(sum!=1)
		{
			if(sum%2==0)
				sum=sum/2;
			else
				sum=3*sum+1;
			i++;
		}
		if(str<i)
			str=i+1;
		i=0;
	}
	return str;
}
int main()
{
	int a,b;
	while(cin>>a>>b)
	{
		cout<<a<<" "<<b<<" "<<length(a,b)<<endl;
	}
	return 0;
}
为啥编译错误啊。。。
2019-07-08 15:54:22
#include<iostream>
using namespace std;
int three(int a,int b);
int main()
{
	int a,b;
	while(cin>>a)
	{
		cin>>b;
		int t;
		if(a>b) { t=a; a=b; b=t;
		}
		three(a,b);
	}

	return 0;
}

int three(int a,int b)
{
	int i,n=0,max=0;
	for( i=a;i<=b;i++)
	{	
		n=1;
		int j=i;
		while(j!=1)
		{
			if(j%2==0)
			j=j/2;
			else j=j*3+1;
			n++;
				
		}
		if(n>max)	max=n;
	}
	
	cout<<a<<" "<<b<<" "<<max<<endl;
}
我的为啥只过%30
2019-01-24 16:32:32
  • «
  • 1
  • »