Chương trình phải chấp nhận một số nguyên N làm đầu vào. Chương trình phải in hiệu tuyệt đối giữa hai chữ số đầu tiên và hai chữ số cuối cùng trong N làm đầu ra
[Các] Điều kiện biên.
10^3
Định dạng đầu vào.
Dòng đầu tiên chứa giá trị của N.
Định dạng đầu ra.
Dòng đầu tiên ghi hiệu tuyệt đối giữa hai chữ số đầu và hai chữ số cuối của N.
Ví dụ Đầu vào/Đầu ra 1.
Đầu vào.
21546
Đầu ra.
25
Giải thích.
Hai chữ số đầu tiên trong 21546 là 21.
Hai chữ số cuối cùng trong 21546 là 46.
Hiệu tuyệt đối của 21 và 46 là 25.
Ví dụ Đầu vào/Đầu ra 2.
Đầu vào.
351684617
Đầu ra.
18
input_n=input[].strip[]
num1=input_n[0:2]
num2=input_n[-2:]
num1,num2=int[num1],int[num2]
print[abs[num1-num2]]
Đăng lại
Phản ứng của bạn là gì?
Kinh ngạc
0đang yêu
1Rất hữu ích
0vỗ tay
0- chữ số
01626
Cho số nguyên dương N [ít nhất chứa hai chữ số]. Nhiệm vụ là viết chương trình Python để cộng chữ số đầu tiên và chữ số cuối cùng của số N đã cho
ví dụ
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.
Input: N = 73 Output: 10
Phương pháp 1. Triển khai chuỗi
- Lấy đầu vào ở dạng Chuỗi hoặc đánh máy đã cho đầu vào ở dạng Chuỗi
- Bây giờ, chọn chỉ mục thứ 0 của Chuỗi và nhập nó vào Số nguyên và lưu trữ nó trong một biến
- Điều tương tự với chỉ mục -1 và cũng lưu trữ trong một biến khác
- Bây giờ thêm hai biến này và
- in chúng dưới dạng Đầu ra
Ghi chú. Chúng ta có thể truy cập phần tử đầu tiên của Chuỗi bằng chuỗi [0] và phần tử cuối cùng của Chuỗi bằng chuỗi [-1]
Biểu diễn chuỗi
Python3
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.50
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.51
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.52
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.53
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.54
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.51
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.52
Input: N = 73 Output: 100
Input: N = 73 Output: 101
Input: N = 73 Output: 102
Input: N = 73 Output: 103
Input: N = 73 Output: 104
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.52
Input: N = 73 Output: 106
Input: N = 73 Output: 107
Input: N = 73 Output: 108
Input: N = 73 Output: 109
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.20
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.52
Input: N = 73 Output: 106
Input: N = 73 Output: 107
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.24
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.25
Input: N = 73 Output: 109
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.27
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.28
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.52
Input: N = 73 Output: 104
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.501
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.20
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.503
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.504
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.505____1506
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.507
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.508
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.509
đầu ra
Cộng chữ số đầu và chữ số cuối của số là 8
Độ phức tạp về thời gian. O[1] kể từ khi thực hiện các hoạt động liên tục
Không gian phụ trợ. O[1] vì sử dụng không gian cố định cho các biến
Phương pháp 2. Giải nó bằng một số nguyên
- Chúng tôi đã đưa ra một số nguyên dương
- Sau khi chia cho 10, lưu trữ phần còn lại trong một biến kết quả
- Tiếp tục vòng lặp cho đến khi số nhỏ hơn 9
- Mỗi lần trong vòng lặp, chia số cho 10 [chia số nguyên]
- Sau khi kết thúc vòng lặp
- Thêm số vào biến kết quả
- Hiển thị biến kết quả dưới dạng đầu ra
Ghi chú. Bất cứ khi nào chúng tôi chia bất kỳ số nào cho 10, chúng tôi nhận được chữ số cuối cùng là phần còn lại. Nếu chia một số bất kỳ cho 100 thì dư hai chữ số tận cùng
Input: N = 73 Output: 1025 ________ 2261Input: N = 73 Output: 10257 ________ 2289Input: N = 73 Output: 1020Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6862Input: N = 73 Output: 10264Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6916Input: N = 73 Output: 10289Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.707Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6867
Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6869Input: N = 73 Output: 1025Input: N = 73 Output: 1028Input: N = 73 Output: 1029
Input: N = 73 Output: 10274Input: N = 73 Output: 10248Input: N = 73 Output: 10276Input: N = 73 Output: 1025Input: N = 73 Output: 1025Input: N = 73 Output: 10278Input: N = 73 Output: 1025Input: N = 73 Output: 1028Input: N = 73 Output: 10281Input: N = 73 Output: 10282Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.707Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.708
Input: N = 73 Output: 10285________ 2261 ________ 2257 ________ 2234 ________ 1752
Input: N = 73 Output: 10290Input: N = 73 Output: 10291____2257Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.682Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.708Input: N = 73 Output: 10290Input: N = 73 Output: 10296
Input: N = 73 Output: 10297C#
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6898Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6899Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.80Input: N = 73 Output: 10201
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.806Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6957Input: N = 73 Output: 1025Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.75Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.843Input: N = 73 Output: 1020Input: N = 73 Output: 1021Input: N = 73 Output: 1020Input: N = 73 Output: 1023Input: N = 73 Output: 1025Input: N = 73 Output: 1024Input: N = 73 Output: 1022____16902Input: N = 73 Output: 1022Input: N = 73 Output: 1020Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6905____220Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8021Input: N = 73 Output: 1025Input: N = 73 Output: 1022____16911Input: N = 73 Output: 1022Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6913____220____16982Input: N = 73 Output: 1020Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8030Input: N = 73 Output: 1025Input: N = 73 Output: 1022____16919________ 222 ________ 228 ________ 229
Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930Input: N = 73 Output: 1025Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.931Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.843Input: N = 73 Output: 1020Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.933Input: N = 73 Output: 1020Input: N = 73 Output: 1023Input: N = 73 Output: 1025Input: N = 73 Output: 1024 Input: N = 73 Output: 1022____1938Input: N = 73 Output: 1022Input: N = 73 Output: 1028Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.691Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930Input: N = 73 Output: 1025Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.693Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.805Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.843Input: N = 73 Output: 10227Input: N = 73 Output: 10259Input: N = 73 Output: 1025Input: N = 73 Output: 1024Input: N = 73 Output: 1022Input: N = 73 Output: 1020Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.699Input: N = 73 Output: 1022Input: N = 73 Output: 10266Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8072Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.682Input: N = 73 Output: 10240Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8078PHP
Input: N = 73 Output: 10274Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.93Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.69
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.75Input: N = 73 Output: 10278Input: N = 73 Output: 1021____2280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.708Input: N = 73 Output: 1024Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6902Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8091Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8092Input: N = 73 Output: 10280Input: N = 73 Output: 10218
Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6911Input: N = 73 Output: 1025Input: N = 73 Output: 10280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8099Input: N = 73 Output: 10280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8401Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8091Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8403
Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6919Input: N = 73 Output: 1025Input: N = 73 Output: 1028Input: N = 73 Output: 10280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.752Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.931Input: N = 73 Output: 10278Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.933____2280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.708Input: N = 73 Output: 1024Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.938Input: N = 73 Output: 1025Input: N = 73 Output: 1028Input: N = 73 Output: 10289Input: N = 73 Output: 10280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9316Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9318________ 2280 ________ 19320
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9321Input: N = 73 Output: 1021____2280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8431Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.682Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8433Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9327Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.933____2280Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8437Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9331____1752
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8440 Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8441Javascript
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9335
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8443Input: N = 73 Output: 10276
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.75________ 2278 ________ 19342
Input: N = 73 Output: 1024Input: N = 73 Output: 1025Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6902Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8453
Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6911Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8457
Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.6919Input: N = 73 Output: 1025Input: N = 73 Output: 1028Input: N = 73 Output: 1029Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.931Input: N = 73 Output: 10278Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8466Input: N = 73 Output: 1025Input: N = 73 Output: 1025Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.938Input: N = 73 Output: 1025Input: N = 73 Output: 1028Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8472Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.930
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9318Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9379Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8476Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.682Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.708Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8479Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8480Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.708
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.8482
Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two [1 + 7] is equal to 8.9388Đầu ra
Input: N = 73 Output: 102Độ phức tạp về thời gian. O[1]
Không gian phụ. Ô[1]Lưu ý quan trọng. log10[] là một hàm toán học có trong toán học. tập tin tiêu đề h. Nó trả về giá trị log cơ số 10 của tham số đã truyền cho hàm log10[].