-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday7.cpp
More file actions
69 lines (53 loc) · 1.86 KB
/
day7.cpp
File metadata and controls
69 lines (53 loc) · 1.86 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
// A mountain shepherd, wants to send special winter greetings to his fellow shepherds in nearby villages. However, his list of greetings is all combined into a single string using various symbols as separators, such as '.' , '@', '!' etc. Your task is to help him separate these strings into individual greetings so he can send them out clearly.
// Input Format
// The first line will be T, the number of test cases.
// Each test case will provide a single string containing greetings combined with special characters.
// Constraints
// 1≤ T≤ 500
// 1 ≤ S.size() ≤ 1000
// S contains alphanumeric characters and special symbols: {~,!,@,#,$,%,^,&,*,(,),_,+}
// Output Format
// For each test case, output the list of separated strings containing greetings.
// Sample Input 0
// 1
// warm@winter!greetings_to_you
// Sample Output 0
// warm
// winter
// greetings
// to
// you
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main() {
int T;
cin >> T;
cin.ignore();
set<char> delimiters = {'~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
while (T--) {
string S;
getline(cin, S);
vector<string> greetings;
string currentGreeting;
for (char c : S) {
if (delimiters.find(c) != delimiters.end()) {
if (!currentGreeting.empty()) {
greetings.push_back(currentGreeting);
currentGreeting.clear();
}
} else {
currentGreeting += c;
}
}
if (!currentGreeting.empty()) {
greetings.push_back(currentGreeting);
}
for (const string& greeting : greetings) {
cout << greeting << endl;
}
}
return 0;
}