[Làm Quen OJ]. Bài 18. Hoán vị giá trị 2 số
View as PDF
Submit solution
Points:
1.00 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Problem source:
Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho 2 số nguyên a, b bạn hãy hoán đổi giá trị 2 số a và b sau đó tính giá trị biểu thức 128 * a + 97 * b + 1000 in ra màn hình. Để hoán đổi giá trị a, b bạn có thể dùng swap(a, b) hoặc dùng biến tạm như sau : int tmp = a; a = b; b = tmp;
Đầu vào
Dòng duy nhất gồm 2 số a, b
Ràng buộc
0<=a,b<=10^9
Đầu ra
In ra a b sau khi hoán đổi giá trị
Ví dụ
Input 01
12 16
Output 01
4212
Comments
Một cách khác để hoán vị 2 số
FULL AC:
def swapandcompute(a: int, b: int) -> int: a, b = b, a return 128 * a + 97 * b + 1000
def main(): try: a, b = map(int, input().strip().split()) print(swapandcompute(a, b)) except Exception as e: print(f"Input error: {e}")
if name == "main": main()
3 testcases sau cho a, b lớn hơn 10^9 -.-.
include <bits/stdc++.h>
using namespace std;
int main(){ long long a, b; cin >> a >> b; swap(a,b); cout << 128 * a + 97 * b + 1000 << endl; return 0; }
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.