|
|
back to boardAC_Sol in c++ Posted by Adkham 7 Nov 2017 23:33 #include<iostream> #include<string> using namespace std; int main() { string box1[3][3] = { "Alice", "Ariel","Aurora", "Phil", "Peter", "Olaf", "Phoebus", "Ralph", "Robin" }; string box2[3][3] = { "Bambi", "Belle", "Bolt", "Mulan", "Mowgli", "Mickey", "Silver", "Simba", "Stitch" }; string box3[3][3] = { "Dumbo", "Genie", "Jiminy", "Kuzko", "Kida", "Kenai", "Tarzan", "Tiana", "Winnie" }; int n, step; string names; bool here1, here2, here3; here2 = here3 = false; here1 = true; step = 0; cin >> n; for (int m = 0; m < n; m++) { cin >> names; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (box1[i][j] == names) { here1 = true; if (here2) { step++; } else if (here3) { step = step + 2; } here2 = false; here3 = false; break; } } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (box2[i][j] == names) { here2 = true; if (here1) { step++; } else if (here3) { step++; } here1 = false; here3 = false; break; } } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (box3[i][j] == names) { here3 = true; if (here2) { step++; } else if (here1) { step = step + 2; } here1 = false; here2 = false; break; } } } } cout << step << endl; return 0; } Re: AC_Sol in c++ #include <iostream> #include <string> #include <cmath> int32_t get_post_case_offset(const std::string& receiver) { uint32_t out = 0; switch (receiver[0]){ case 'A': case 'P': case 'O': case 'R': out = 0; break;
case 'B': case 'M': case 'S': out = 1; break; default: out = 2; } return out; } std::string get_receiver(){ std::string out; std::cin >> out; return std::move(out); } int main() { uint32_t n; std::cin >> n; uint32_t steps = 0; int32_t last_offset = 0;
for (;n;n--){ int32_t offset = get_post_case_offset(get_receiver()); steps += abs(last_offset - offset); last_offset = offset; } std::cout << steps << std::endl;
return 0; } |
|
|