[Làm Quen OJ]. Bài 20. Sử dụng cout 2

View as PDF

Submit solution

Points: 1.00
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Author:
Problem source:
28Tech
Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho số N, bạn hãy in ra số N với 6 chữ số, nếu N không đủ 6 chữ số thì tiến hành chèn 0 và dấu # vào đầu cho đủ 6 chữ số.

Cú pháp để in ra 1 số nguyên n với độ rộng K, điền đầy ký tự C vào đầu nếu không đủ K chữ số

#include <iomanip>
cout << setw(K) << setfill(C) << n << endl;

Đầu vào

Dòng duy nhất chứa số N


Ràng buộc

0<=N<10^6


Đầu ra

Dòng 1 in ra N với số 0 được chèn vào trước

Dòng 2 in ra N với dấu # được chèn vào trước


Ví dụ

Input 01
850
Output 01
000850
###850

Comments

Please read the guidelines before commenting.



  • -2
    Try_hardxx  commented on Oct. 27, 2024, 4:20 a.m.

    include<bits/stdc++.h>

    using namespace std;

    int main(){ long long a,b,c,d; cin >> a; cout << setw(6) << setfill('0') << a <<'\n'; cout << setw(6) << setfill('#') << a;

    }


  • 2
    trong_nghia_245  commented on Sept. 4, 2024, 3:27 p.m.

    Lời giải cho python

    enter code herex = int(input())
    enter code here = print('{:06d}'.format(x))
    enter code here = print('{:>6d}'.format(x).replace(' ', '#'))