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

1059 C语言竞赛 更多...

函数

bool is_prime (int n)
 
int main (istream &cin, ostream &cout)
 
 TEST (b1059, case1)
 

详细描述

1059 C语言竞赛

函数说明

◆ is_prime()

bool pat::b::b1059::is_prime ( int  n)

在文件 pat.cpp2077 行定义.

2077 {
2078 for(int i = 2; i <= sqrt(n); i++) {
2079 if(n % i == 0) {
2080 return false;
2081 }
2082 }
2083 return true;
2084 }

被这些函数引用 luogu::P5723::main(), luogu::P1217::main(), luogu::P1125::main() , 以及 main().

◆ main()

int pat::b::b1059::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp2086 行定义.

2086 {
2087 int n;
2088 cin >> n;
2089 unordered_map<string, string> um;
2090 for(int rank = 1; rank <= n; rank++) {
2091 string id;
2092 cin >> id;
2093 if(rank == 1) {
2094 um[id] = "Mystery Award";
2095 } else if(is_prime(rank)) {
2096 um[id] = "Minion";
2097 } else {
2098 um[id] = "Chocolate";
2099 }
2100 }
2101 int k;
2102 cin >> k;
2103 while(k-- != 0) {
2104 string id;
2105 cin >> id;
2106 if(static_cast<unsigned int>(um.contains(id)) == 0U) {
2107 cout << id << ": Are you kidding?" << endl;
2108 } else {
2109 cout << id << ": " << um[id] << endl;
2110 um[id] = "Checked";
2111 }
2112 }
2113 return 0;
2114 }
bool is_prime(unsigned int n)
Definition: pat.cpp:4422

引用了 is_prime().

被这些函数引用 TEST().

◆ TEST()

pat::b::b1059::TEST ( b1059  ,
case1   
)

在文件 pat_test.cpp902 行定义.

902 {
903 istringstream in("6\n"
904 "1111\n"
905 "6666\n"
906 "8888\n"
907 "1234\n"
908 "5555\n"
909 "0001\n"
910 "6\n"
911 "8888\n"
912 "0001\n"
913 "1111\n"
914 "2222\n"
915 "8888\n"
916 "2222");
917 auto out = ostringstream();
918 main(in, out);
919 const auto ans = out.str();
920 ASSERT_EQ("8888: Minion\n"
921 "0001: Chocolate\n"
922 "1111: Mystery Award\n"
923 "2222: Are you kidding?\n"
924 "8888: Checked\n"
925 "2222: Are you kidding?\n",
926 out.str());
927 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().