[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:
28Tech
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ố ab 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

Please read the guidelines before commenting.



  • 0
    Nguyen_Minh_Khanh_CPP  commented on Jan. 2, 2026, 6:34 a.m.

    Một cách khác để hoán vị 2 số

    a = a + b;
    b = a - b;
    a = a - b;
    

  • -2
    L8_DuongThanhKhiem  commented on Nov. 22, 2025, 4:13 a.m.

    FULL AC:

    #include <bits/stdc++.h>
    using namespace std;
    long long a, b;
    int main(){
        cin >> a >> b;
        swap(a, b);
        cout << (long long)128 * a + 97 * b + 1000;
        return 0;
    }
    

  • -1
    bengokyeuanh99  commented on April 16, 2025, 11:37 a.m.

    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()


  • 0
    nmtuong_cpp  commented on April 16, 2025, 7:28 a.m.

    3 testcases sau cho a, b lớn hơn 10^9 -.-.


  • -1
    nguyen_trung_cpp  commented on Nov. 6, 2024, 7:49 p.m.

    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; }


  • -7
    Try_hardxx  commented on Oct. 27, 2024, 4:07 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    fuchs  commented on May 27, 2024, 6:59 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -11
    Itachi  commented on April 30, 2024, 12:55 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.