在一行上输入两个整数
代表已有的数字。
在一行上输出一个整数代表你所找到的第三个数字。
如果存在多个解决方案,您可以输出任意一个,系统会自动判定是否正确。注意,自测运行功能可能因此返回错误结果,请自行检查答案正确性。
3 2
1
是一个以
为首项、
为公差的等差数列。当然,输出
也是一个正确的答案。
3 2
4
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int dif = Math.abs(a - b);
int max = a > b ? a : b;
int c = max + dif;
System.out.println(c);
}
} #include <iostream>
#include <cmath>
using namespace std;
int function(int a, int b){
int delta = abs(a - b);
return a > b ? b - delta : a - delta;
}
int main() {
int a = 0;
int b = 0;
cin >> a >> b;
int c = function(a, b);
cout << c;
}
n,m=map(int,input().split()) d=abs(n-m) print(max(n,m)+d)
用num1 num2来接收控制器来的两个整数,计算出他们的差值,找出num1和num2的较小数,用num1减去 他们的差值,即可得到答案。
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int num1 = in.nextInt();
int num2 = in.nextInt();
int minornum = Math.min(num1, num2);
int count = Math.abs(num1 - num2);
System.out.println(minornum - count);
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int b = in.nextInt();
if (b > a) {
System.out.println(b + b - a);
} else {
System.out.println(a + a - b);
}
break;
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int a = in.nextInt();
int b = in.nextInt();
int c = 0;
if (a > b) {
int temp = a - b;
c = a + temp;
} else if (a < b) {
int temp = b - a;
c = b + temp;
} else if (a == b) {
c = a;
}
System.out.print(c);
}
}