Submission 9130194
ID | DATE | PROBLEM | STATUS | CPU | LANG | TEST CASES |
---|---|---|---|---|---|---|
9130194 | 17:51:53 | A Rank Problem | Accepted | 0.00 s | C++ | 27/27 |
Solution 1: Use STL Vector C++
Files submitted
#include<bits/stdc++.h>
#define all a.begin(),a.end()
using namespace std;
int n, m;
vector<string> a;
string win, lose;
int main(){
cin >> n >> m;
for(int i=1; i<=n; i++) a.push_back("T"+to_string(i));
while(m--){
cin >> win >> lose;
if (find(all, win) < find(all, lose)) continue;
a.erase(find(all, lose));
a.insert(find(all, win) + 1, lose);
}
for(auto x:a) cout<<x<<" ";
}
Submission 9129968
ID | DATE | PROBLEM | STATUS | CPU | LANG | TEST CASES |
---|---|---|---|---|---|---|
9129968 | 16:40:02 | A Rank Problem | Accepted | 0.02 s | C++ | 27/27 |
Solution 2: Use array c++
Files submitted
#include<bits/stdc++.h>
using namespace std;
const int N= 1000111;
string a[N], win, lose;
int n, m;
bool NotChange(){
int posWin, posLose;
for(int i=1; i<=n; i++){
if (a[i]==win) posWin= i;
if (a[i]==lose) posLose= i;
}
if (posWin < posLose) return true;
return false;
}
int main(){
cin >> n >> m;
for(int i=1; i<=n; i++) a[i]= "T"+to_string(i);
while(m--){
cin >> win >> lose;
if (NotChange()) continue;
//delete element in array
for(int i=1; i<=n; i++)
if (a[i] == lose) for(int j=i; j<n; j++) a[j]= a[j+1];
//insert element in array
for(int i=1; i<=n; i++)
if (a[i] == win){
for(int j=n; j>i; j--) a[j+1]= a[j];
a[i+1]= lose;
}
}
for(int i=1; i<=n; i++) cout<<a[i]<<" ";
}
No comments:
Post a Comment