-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeGenerationAndStandardization.cpp
More file actions
67 lines (53 loc) · 1.37 KB
/
CodeGenerationAndStandardization.cpp
File metadata and controls
67 lines (53 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Problem: Code generation and standardization in DBMS
Description
In DataBase Management Systems, we need to generate the keys for records created.
In many cases, a key is generated by generating a non-negative integer and is
standardized under a string with fixed length L (by filling characters 0 at the
beginning of the integer util the length is equal to L). For example,
if the fixed-length L is 5, the key generated from 123 is the string 00123.
Given a positive integer n and L, and a sequence of integers a1, a2, ..., an.
Write a program for generating corresponding keys k1, k2, ..., kn.
Input
Line 1: contains n and L (1 <= n <= 1000000, 2 <= L <= 50)
Line i+1 (i = 1,...,n): contains ai (1 <= ai <= 2000000), ai < 10
L
Output
Line i (i = 1,..., n): contains the key ki
Example
Input
5 6
54
39
40
78
1
Output
000054
000039
000040
000078
000001
*/
#include <iostream>
#include <cstdio> // Thêm thư viện để sử dụng scanf
using namespace std;
int main() {
int n, L;
scanf("%d %d", &n, &L);
for (int i = 0; i < n; i++) {
int num;
scanf("%d", &num);
int zerosToAdd = L;
int tempNum = num;
while (tempNum > 0) {
tempNum /= 10;
zerosToAdd--;
}
for (int j = 0; j < zerosToAdd; j++) {
printf("0");
}
printf("%d\n", num);
}
return 0;
}