problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing3385 命名空间参考

  1. 玛雅人的密码
更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (acwing3385, case1)
 

详细描述

  1. 玛雅人的密码

函数说明

◆ main()

int acwing::acwing3385::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing408.cpp624 行定义.

624 {
625 int n;
626 string s;
627 cin >> n >> s;
628 unordered_set<string> used;
629 queue<pair<string, int>> q = queue<pair<string, int>>();
630 q.push(make_pair(s, 0));
631 used.insert(s);
632 while(!q.empty()) {
633 auto [current_s, current_step] = q.front();
634 if(current_s.find("2012") != string::npos) {
635 cout << current_step;
636 return 0;
637 }
638 q.pop();
639 for(int i = 0, j = 1; j < n; i++, j++) {
640 string next_s = current_s;
641 swap(next_s[i], next_s[j]);
642 if(used.find(next_s) == used.end()) {
643 used.insert(next_s);
644 q.push(make_pair(next_s, current_step + 1));
645 }
646 }
647 }
648 cout << -1;
649 return 0;
650 }

被这些函数引用 TEST().

◆ TEST()

acwing::acwing3385::TEST ( acwing3385  ,
case1   
)

在文件 acwing408_test.cpp1098 行定义.

1098 {
1099 istringstream in("5\n"
1100 "02120\n");
1101 auto out = ostringstream();
1102 main(in, out);
1103 const auto ans = out.str();
1104 ASSERT_EQ("1",
1105 ans);
1106 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().