Skip to content

Instantly share code, notes, and snippets.

@BreadFish64
Created October 3, 2019 15:44
Show Gist options
  • Save BreadFish64/ae4f2612aa2f21f3d03c49e8b23bcd6e to your computer and use it in GitHub Desktop.
Save BreadFish64/ae4f2612aa2f21f3d03c49e8b23bcd6e to your computer and use it in GitHub Desktop.
#include <array>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
constexpr double PI = 3.14159265358979323846;
int main() {
std::array<std::pair<double, double>, 'Z' - 'A' + 1> char_coords{};
double disk_rad = 0.;
std::cin >> disk_rad;
for (unsigned i = 0; i < 26; ++i) {
char letter;
double angle = 0.;
std::cin >> letter >> angle;
angle *= PI / 180.;
char_coords[letter - 'A'] = {std::cos(angle) * disk_rad, std::sin(angle) * disk_rad};
}
std::string message;
std::cin >> std::ws;
std::getline(std::cin, message);
double length = 0.;
std::pair<double, double> last_coords = {0., 0.};
for (char c : message) {
c = std::toupper(c);
if ('A' <= c && c <= 'Z') {
auto coords = char_coords[c - 'A'];
length +=
std::hypot(coords.first - last_coords.first, coords.second - last_coords.second);
last_coords = coords;
}
}
std::cout << std::ceil(length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment