-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclosingtheloop.cpp
64 lines (60 loc) · 1.46 KB
/
closingtheloop.cpp
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
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <ctype.h>
#include <unordered_set>
using namespace std;
int main(){
int cases;
int dataNum;
int smaller;
string tempString;
vector<int> red;
vector<int> blue;
cin >> cases;
for (int i = 0; i < cases; i++){
cin >> dataNum;
int total = 0;
for (int j = 0; j < dataNum; j++){
cin >> tempString;
//cout << tempString << endl;
//cout << tempString.at(tempString.length() - 1) << endl;
if (tempString.at(tempString.length() - 1) == 'R'){
red.push_back(stoi(tempString));
}
else if (tempString.at(tempString.length() - 1) == 'B'){
blue.push_back(stoi(tempString));
}
}
//cout << red.size() << endl;
//cout << blue.size() << endl;
sort(red.begin(),red.end());
sort(blue.begin(), blue.end());
if (red.size() > blue.size()){
smaller = blue.size();
}
else{
smaller = red.size();
}
if (smaller == 0){
cout << "Case #" << i + 1 << ": " << total << endl;
red.erase(red.begin(), red.end());
blue.erase(blue.begin(), blue.end());
continue;
}
for (int j = 0; j < smaller; j++){
total += red[red.size() - j - 1] - 1;
//cout << total << endl;
total += blue[blue.size() - j -1] - 1;
//cout << total << endl;
}
cout << "Case #" << i + 1 << ": " << total << endl;
red.erase(red.begin(),red.end());
blue.erase(blue.begin(),blue.end());
}
return 0;
}