-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1283.cpp
More file actions
70 lines (63 loc) · 1.36 KB
/
1283.cpp
File metadata and controls
70 lines (63 loc) · 1.36 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
68
69
70
#include <iostream>
#include <cstring>
#include "stdio.h"
using namespace std;
int N;
string arr[31];
char shortcut[27] = { 0, };
int space[6] = { 0, };
int index(string str, int n) {
return tolower(str[n]) - 96;
}
int allocShortcut(string str) {
int len = str.length(), i = 0, idx = 0, spaceNum = 0;
while (i != len) {
idx = index(str, i);
if (str[i] == ' ' && idx) space[spaceNum++] = i + 1;
i++;
}
i = 0, idx = index(str, 0);
if (!shortcut[idx]) {
shortcut[idx] = 1;
return i;
}
for (int a = 0; a < spaceNum; a++) {
idx = index(str, space[a]);
if (!shortcut[idx] && idx) {
shortcut[idx] = 1;
return space[a];
}
}
i = 1;
while (i != len) {
idx = index(str, i);
if (str[i] == '\n') return 100;
if (str[i] != ' ' && !shortcut[idx] && idx) {
shortcut[idx] = 1;
return i;
}
i++;
}
memset(space, 0, sizeof(space));
return 100;
}
int main() {
char buffer[100];
cin >> N;
for (int i = 0; i <= N; i++) {
memset(buffer, 0, sizeof(buffer));
if(fgets(buffer, sizeof(buffer), stdin) != NULL)
arr[i] = buffer;
}
for (int i = 1; i <= N; i++) {
int idx = allocShortcut(arr[i]);
for (int j = 0; j < arr[i].length(); j++) {
if (idx == j) cout << '[';
if(arr[i][j] != '\n')cout << arr[i][j];
if (idx == j) cout << ']';
}
if (i != N) cout << endl;
}
return 0;
}
//aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee