Số đẹp
View as PDF
Submit solution
Points:
0.01 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
sodep.inp
Output:
sodep.out
Author:
Problem type
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch
~T~ là tổng các chữ số của ~N~. Số ~N~ được gọi là số đẹp nếu hàng đơn vị của ~T~ là số ~9~. Ví dụ số ~18~ là số đẹp vì có ~T = 1 + 8 = 9~.
Cho một số ~N~, hỏi ~N~ có phải là số đẹp hay không?
Input
Từ tệp văn bản SODEP.INP chứa một số tự nhiên ~N~ duy nhất (~0 \leq N \leq 10^9~).
Output
Đưa ra tệp SODEP.OUT số 1 nếu ~N~ là số đẹp, ngược lại ghi số 0.
Sample Input 1
27
Sample Output 1
1
Sample Input 2
111
Sample Output 2
0

Comments
Bài này rất hợp cho các bạn mới vài note: thay vì nhập N vào bài dưới dạng số thì nên dùng xâu để tính tổng chữ số dễ hơn, vì for tiện hơn, mà với N<=1e9 thì làm như nào chả đc
why we have to use string while n <= 1e9?
MPC
bài này dùng số học
This comment is hidden due to too much negative feedback. Show it anyway.
Pls downvote
This comment is hidden due to too much negative feedback. Show it anyway.
code nha moi nguoi:
include <bits/stdc++.h>
using namespace std; long long kq(long long n) { long long so=0; while(n>0) { so=so+n%10; n=n/10; } return so; } int main() { ifstream cin("sodep.inp"); ofstream cout("sodep.out"); long long n; cin>>n; if(kq(n)==9||kq(n)%10==9)cout<<"1"; else cout<<"0"; 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.
with open("SODEP.INP", "r") as f: n = int(f.read().strip())
Tính tổng chữ số của N
total = sum(int(digit) for digit in str(n))
Kiểm tra có phải số đẹp không
is_beautiful = 1 if total % 10 == 9 else 0
Ghi kết quả ra file
with open("SODEP.OUT", "w") as f: f.write(str(is_beautiful))
help me