算法题,逆出来大概是这样:
#include <cstdlib>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>
using namespace std;
int key1[40] = {3, 4, 1, 1, 8, 7, 4, 5, 2, 0, 1, 1, 2, 9, 8, 1, 2, 5, 2, 7,
3, 1, 9, 6, 3, 8, 2, 5, 10, 2, 3, 7, 10, 6, 9, 8, 7, 8, 1, 0};
vector<string> tab1 = {"cnss{", "Never", "gonna", /* ... */};
struct Edge {
int to;
int weight;
};
struct Element { // maybe 0x40
int index;
vector<Edge> edges;
std::string str;
// other fields
};
Element arr[11];
void init() {
for (int i = 0; i <= 10; ++i) {
arr[i].index = i;
arr[i].str = tab1[i];
}
for (int j = 0; j <= 38; j += 3) {
int u = key1[j];
int v = key1[j + 1];
int w = key1[j + 2];
addEdge(arr[u], v, w);
addEdge(arr[v], u, w);
}
}
int main() {
string input;
cin >> input;
stringstream ss(input);
int nowEdge = 0, sum = 0;
string i;
bool flag = false;
while (getline(ss, i, '_')) {
// 查找i在tab中的位置
int index = -1;
for (auto j : tab1) {
index++;
if (j == i) {
break;
}
}
if (index == -1) {
cout << "Wrong!" << endl;
return 0;
}
if (index) {
for (auto j : arr[nowEdge].edges) {
if (j.to == index) {
nowEdge = j.to;
sum += j.weight;
flag = true;
break;
}
}
if (!flag) {
cout << "Wrong!" << endl;
return 0;
}
}
}
}
string 24byte+
这里用的是临接表求最短路(唯一)