-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInsert Digit.c
71 lines (67 loc) · 1.56 KB
/
Insert Digit.c
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
68
69
70
71
// https://codeforces.com/problemset/problem/1811/A
#include <stdio.h>
int main(){
int t, n, f;
char d;
scanf("%d", &t);
while (t--){
f = 0;
scanf("%d %c", &n, &d);
char num[n];
scanf(" %s", &num);
for (int i = 0; i < n; i++){
if (num[i] < d && f == 0){
printf("%c", d);
i--; f = 1;
continue;
}
printf("%c", num[i]);
}
if (f == 0)
printf("%c", d);
printf("\n");
}
return 0;
}
// #include <stdio.h>
// #include <string.h>
// int main()
// {
// int t, n, f;
// char d;
// scanf("%d", &t);
// for (int i = 0; i < t; i++)
// {
// f = 0;
// scanf("%d %c", &n, &d);
// char number[n + 2];
// scanf(" %s", &number);
// for (int i = 0; i < n; i++)
// {
// if (number[i] < d)
// {
// char temp = number[i];
// number[i] = d;
// for (int j = i + 1; j < n + 1; j++)
// {
// char x = number[j];
// number[j] = temp;
// temp = x;
// }
// f = 1;
// break;
// }
// }
// if (f == 0)
// {
// number[n] = d;
// }
// for (int j = 0; j < n+1; j++)
// {
// printf("%c", number[j]);
// }
// printf("\n");
// // puts(number);
// }
// return 0;
// }