A + B Problem
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题目描述
给两个数\(a\)与\(b\),执行以下操作:
定义两个变量\(sum\)和\(carry\)
使\(sum\)等于\(a\)异或\(b\)
使\(carry\)等于\(a\)与\(b\)后左移一位
使\(a\)等于\(sum\)
使\(b\)等于\(carry\)
重复2~5步直到\(b\)等于\(0\)
输出\(a\)
格式
输入
Two integers x and y, satisfying 0 <= x, y <= 32767.
输出
One integer, the sum of x and y.
样例
输入
123 500
输出
623
数据约束
1s, 1024KiB for each test case.
提示
Free Pascal Code
var a,b:longint;
begin
readln(a,b);
writeln(a+b);
end.
C Code
#include <stdio.h>
int main(void)
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
return 0;
}
C++ Code
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
return 0;
}
Python Code
a, b = [int(i) for i in raw_input().split()]
print(a + b)
Java Code
import java.io.*;
import java.util.Scanner;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a + b);
}
}