B - Cycle Hit
Problem Statement
You are given four strings S1S1, S2S2, S3S3, and S4S4.
Determine whether this sequence of strings has one of each of the following:H
,2B
,3B
, andHR
.
Here, it is guaranteed that every SiSi isH
,2B
,3B
, orHR
.Constraints
- Each SiSi is
H
,2B
,3B
, orHR
.Input
Input is given from Standard Input in the following format:
S1S1 S2S2 S3S3 S4S4Output
If the given sequence of strings has one of each of
H
,2B
,3B
, andHR
, printYes
.
Otherwise, printNo
.Sample Input 1 Copy
Copy
3B HR 2B HSample Output 1 Copy
Copy
YesWe have one of each of
H
,2B
,3B
, andHR
.Sample Input 2 Copy
Copy
2B 3B HR 3BSample Output 2 Copy
Copy
NoWe have no
H
.
尝试用向量来写,注意输出的大小写
#include <bits/stdc++.h>
using namespace std;
int main(){
string s[5];
for(int i = 0;i < 4; i++)
cin >> s[i];
string c[4] = {"HR", "3B", "2B", "H"};
vector<string> b(c, c + 4), a;
for(int i = 0; i < 4; i ++){
a.push_back(s[i]);
for(int j = 0; j < b.size(); j++){
if(a[i] == b[j]) {
b.erase(b.begin()+j, b.begin()+j+1);
}
}
}
if(b.empty()) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}