yipo
7/24/2017 - 4:58 PM

Eb Alto Saxophone Player

Eb Alto Saxophone Player

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

vector<size_t> count_each_finger_presses(const string &song)
{
    typedef bitset<10> fingers;
    static const map<char, fingers> table
    {
        { 'c', fingers("0111001111") },
        { 'd', fingers("0111001110") },
        { 'e', fingers("0111001100") },
        { 'f', fingers("0111001000") },
        { 'g', fingers("0111000000") },
        { 'a', fingers("0110000000") },
        { 'b', fingers("0100000000") },
        { 'C', fingers("0010000000") },
        { 'D', fingers("1111001110") },
        { 'E', fingers("1111001100") },
        { 'F', fingers("1111001000") },
        { 'G', fingers("1111000000") },
        { 'A', fingers("1110000000") },
        { 'B', fingers("1100000000") },
    };

    vector<fingers> diff(song.size());
    transform(song.begin(), song.end(), diff.begin(), [](char note)
    {
        return table.at(note);
    });
    adjacent_difference(diff.begin(), diff.end(), diff.begin(), [](const fingers &curr, const fingers &prev)
    {
        return curr&~prev;
    });

    vector<size_t> sum(10, 0);
    for (const auto &f : diff)
    {
        for (size_t i = 0; i < f.size(); i++)
        {
            if (f[i]) sum[i]++;
        }
    }
    reverse(sum.begin(), sum.end());
    return sum;
}

template <typename T>
string join(const vector<T> &v)
{
    string s;
    for (const auto &x : v) s += (s.empty() ? "" : " ") + to_string(x);
    return s;
}

void test_case()
{
    string song;
    getline(cin, song);
    cout << join(count_each_finger_presses(song)) << endl;
}

int main()
{
    size_t n;
    cin >> n;
    cin.ignore(1, '\n');
    while (n--) test_case();
    return 0;
}