#include<iostream>
#include<algorithm>
using namespace std;
void test(int x,int y,int z)
{
int num1,num2,num3,count;
num1 = y-x;
num2 = z-y;
num3 = z-x;
if(x<0||x>100 || y<0||y>100 || z<0||z>100)
{
printf("输入有误\n");
return;
}
if(x==y && y==z)
{
printf("0\n");
return;
}
else if(x==y)
{
if(num2%2==0)
{
count = num2;
printf("%d\n",count);
}
else
{
count = 2*(num2/2);
count+=2;
printf("%d\n",count);
}
}
else if(y==z)
{
if(num3%2==0)
{
count = num2;
printf("%d\n",count);
}
else
{
count = 2*(num3/2);
count+=2;
printf("%d\n",count);
}
}
else
{
if(num1%2 == 0)
{
count = num1/2 + (z-y);
printf("%d\n",count);
}
else
{
if(num2%2==0)
{
count = num2/2;
count+=num3/2;
count+=2;
printf("%d\n",count);
}
else
{
count+=num3/2;
count+=num2;
printf("%d\n",count);
}
}
}
}
void main()
{
int * arr = new int[3];
for(int i=0;i<3;i++)
{
cin>>arr[i];
}
sort(arr,arr+3);
int x=arr[0];
int y=arr[1];
int z=arr[2];
test(x,y,z);
}代码如上!
输入三个数,操作一任选两个数加一,操作二任选一个数加二。问至少操作几次可以使三个数相等?
最新推荐文章于 2024-01-11 21:52:28 发布
本文提供了一个使用C++编写的程序实例,该程序通过输入三个整数并对其进行排序后,根据特定条件计算并输出结果。文章涉及C++基本语法、流程控制及简单的数学运算。
966





