Language: Java

#include <queue>
#include <vector>
#include <string>
#include <cassert>
#include <iostream>
#include <algorithm>
 
enum class Direction
{
    North = 0,
    East,
    South,
    West,
};
 
struct Number
{
    Number(int t, int f, int r, int l, int b, int btm)
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
 
    int top;
    int front;
    int right;
    int left;
    int back;
    int bottom;
};
 
bool operator==(const Number &lhs, const Number &rhs)
{
    return
        lhs.top == rhs.top &&
        lhs.front == rhs.front &&
        lhs.right == rhs.right &&
        lhs.left == rhs.left &&
        lhs.back == rhs.back &&
        lhs.bottom == rhs.bottom;
}
 
class Dice
{
    public:
        explicit Dice(const Number &number) :number_(number) {}
 
        Dice rotate_to(Direction direction) const
        {
            const Number number = [&](Direction direction) {
                switch(direction)
                {
                    default:
                        assert(!"Invalid Direction.");
                    case Direction::North:
                        return Number(number_.front, number_.bottom, number_.right, number_.left, number_.top, number_.back);
                    case Direction::East:
                        return Number(number_.left, number_.front, number_.top, number_.bottom, number_.back, number_.right);
                    case Direction::South:
                        return Number(number_.back, number_.top, number_.right, number_.left, number_.bottom, number_.front);
                    case Direction::West:
                        return Number(number_.right, number_.front, number_.bottom, number_.top, number_.back, number_.left);
                }
            }(direction);
            return Dice(number);
        }
 
        Number number() const { return number_; }
 
    private:
        Number number_;
};
 
bool operator==(const Dice &lhs, const Dice &rhs)
{
    return lhs.number() == rhs.number();
}
 
Dice make_dice()
{
    int top, front, right, left, back, bottom;
    std::cin >> top >> front >> right >> left >> back >> bottom;
    Number number(top, front, right, left, back, bottom);
    Dice dice(number);
    return dice;
}
 
bool exist(const Dice & dice, const std::vector<Dice> &memo)
{
    return std::find(memo.begin(), memo.end(), dice) != memo.end();
}
 
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
{
    const std::vector<Direction> directions = { Direction::North, Direction::East, Direction::South, Direction::West };
    while(true)
    {
        for(const auto &direction : directions)
        {
            const auto dice = dices.front().rotate_to(direction);
            const auto number = dice.number();
            if(number.top == top && number.front == front)
            {
                return number.right;
            }
            if(exist(dice, memo))
            {
                continue;
            }
            dices.push(dice);
        }
        dices.pop();
    }
}
 
std::vector<int> solve()
{
    const auto dice = make_dice();
    int questions;
    std::cin >> questions;
    std::vector<int> ans;
    for(int i = 0; i < questions; ++i)
    {
        int top, front;
        std::cin >> top >> front;
        std::vector<Dice> memo = { dice };
        std::queue<Dice> dices; dices.push(dice);
        ans.push_back(solve_core(dices, memo, top, front));
    }
    return ans;
}
 
int main()
{
    const auto ans = solve();
    for(const auto &e : ans)
    {
        std::cout << e << std::endl;
    }
    return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <queue>
^
Main.java:2: error: illegal character: '#'
#include <vector>
^
Main.java:3: error: illegal character: '#'
#include <string>
^
Main.java:4: error: illegal character: '#'
#include <cassert>
^
Main.java:5: error: illegal character: '#'
#include <iostream>
^
Main.java:6: error: illegal character: '#'
#include <algorithm>
^
Main.java:8: error: <identifier> expected
enum class Direction
    ^
Main.java:8: error: enum constant expected here
enum class Direction
     ^
Main.java:10: error: <identifier> expected
    North = 0,
         ^
Main.java:13: error: <identifier> expected
    West,
         ^
Main.java:16: error: ';' expected
struct Number
             ^
Main.java:18: error: '.class' expected
    Number(int t, int f, int r, int l, int b, int btm)
               ^
Main.java:18: error: ';' expected
    Number(int t, int f, int r, int l, int b, int btm)
                ^
Main.java:18: error: <identifier> expected
    Number(int t, int f, int r, int l, int b, int btm)
                        ^
Main.java:18: error: <identifier> expected
    Number(int t, int f, int r, int l, int b, int btm)
                               ^
Main.java:18: error: <identifier> expected
    Number(int t, int f, int r, int l, int b, int btm)
                                      ^
Main.java:18: error: <identifier> expected
    Number(int t, int f, int r, int l, int b, int btm)
                                             ^
Main.java:18: error: ';' expected
    Number(int t, int f, int r, int l, int b, int btm)
                                                     ^
Main.java:19: error: ';' expected
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
               ^
Main.java:19: error: ';' expected
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
                         ^
Main.java:19: error: ';' expected
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
                                   ^
Main.java:19: error: ';' expected
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
                                            ^
Main.java:19: error: ';' expected
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
                                                     ^
Main.java:19: error: ';' expected
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
                                                                  ^
Main.java:29: error: ';' expected
bool operator==(const Number &lhs, const Number &rhs)
             ^
Main.java:29: error: <identifier> expected
bool operator==(const Number &lhs, const Number &rhs)
                            ^
Main.java:29: error: illegal start of type
bool operator==(const Number &lhs, const Number &rhs)
                                   ^
Main.java:29: error: <identifier> expected
bool operator==(const Number &lhs, const Number &rhs)
                                               ^
Main.java:29: error: <identifier> expected
bool operator==(const Number &lhs, const Number &rhs)
                                                    ^
Main.java:42: error: illegal start of type
    public:
          ^
Main.java:43: error: illegal start of type
        explicit Dice(const Number &number) :number_(number) {}
                      ^
Main.java:45: error: ';' expected
        Dice rotate_to(Direction direction) const
                                           ^
Main.java:47: error: illegal start of expression
            const Number number = [&](Direction direction) {
            ^
Main.java:47: error: illegal start of expression
            const Number number = [&](Direction direction) {
                                  ^
Main.java:47: error: ';' expected
            const Number number = [&](Direction direction) {
                                                         ^
Main.java:61: error: not a statement
            }(direction);
             ^
Main.java:65: error: ';' expected
        Number number() const { return number_; }
                       ^
Main.java:67: error: illegal start of type
    private:
           ^
Main.java:71: error: ';' expected
bool operator==(const Dice &lhs, const Dice &rhs)
             ^
Main.java:71: error: <identifier> expected
bool operator==(const Dice &lhs, const Dice &rhs)
                          ^
Main.java:71: error: illegal start of type
bool operator==(const Dice &lhs, const Dice &rhs)
                                 ^
Main.java:71: error: <identifier> expected
bool operator==(const Dice &lhs, const Dice &rhs)
                                           ^
Main.java:71: error: <identifier> expected
bool operator==(const Dice &lhs, const Dice &rhs)
                                                ^
Main.java:79: error: not a statement
    std::cin >> top >> front >> right >> left >> back >> bottom;
                                                      ^
Main.java:80: error: ';' expected
    Number number(top, front, right, left, back, bottom);
                 ^
Main.java:80: error: not a statement
    Number number(top, front, right, left, back, bottom);
                  ^
Main.java:80: error: ';' expected
    Number number(top, front, right, left, back, bottom);
                     ^
Main.java:80: error: not a statement
    Number number(top, front, right, left, back, bottom);
                       ^
Main.java:80: error: ';' expected
    Number number(top, front, right, left, back, bottom);
                            ^
Main.java:80: error: not a statement
    Number number(top, front, right, left, back, bottom);
                              ^
Main.java:80: error: ';' expected
    Number number(top, front, right, left, back, bottom);
                                   ^
Main.java:80: error: not a statement
    Number number(top, front, right, left, back, bottom);
                                     ^
Main.java:80: error: ';' expected
    Number number(top, front, right, left, back, bottom);
                                         ^
Main.java:80: error: not a statement
    Number number(top, front, right, left, back, bottom);
                                           ^
Main.java:80: error: ';' expected
    Number number(top, front, right, left, back, bottom);
                                               ^
Main.java:80: error: not a statement
    Number number(top, front, right, left, back, bottom);
                                                 ^
Main.java:80: error: ';' expected
    Number number(top, front, right, left, back, bottom);
                                                       ^
Main.java:81: error: ';' expected
    Dice dice(number);
             ^
Main.java:81: error: not a statement
    Dice dice(number);
              ^
Main.java:81: error: ';' expected
    Dice dice(number);
                    ^
Main.java:85: error: illegal start of type
bool exist(const Dice & dice, const std::vector<Dice> &memo)
           ^
Main.java:85: error: illegal start of type
bool exist(const Dice & dice, const std::vector<Dice> &memo)
                                                      ^
Main.java:85: error: <identifier> expected
bool exist(const Dice & dice, const std::vector<Dice> &memo)
                                                           ^
Main.java:87: error: ';' expected
    return std::find(memo.begin(), memo.end(), dice) != memo.end();
                    ^
Main.java:87: error: ';' expected
    return std::find(memo.begin(), memo.end(), dice) != memo.end();
                                 ^
Main.java:87: error: ';' expected
    return std::find(memo.begin(), memo.end(), dice) != memo.end();
                                             ^
Main.java:87: error: not a statement
    return std::find(memo.begin(), memo.end(), dice) != memo.end();
                                               ^
Main.java:87: error: ';' expected
    return std::find(memo.begin(), memo.end(), dice) != memo.end();
                                                   ^
Main.java:90: error: <identifier> expected
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
                  ^
Main.java:90: error: illegal start of type
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
                                ^
Main.java:90: error: <identifier> expected
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
                                           ^
Main.java:90: error: <identifier> expected
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
                                                         ^
Main.java:90: error: <identifier> expected
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
                                                                         ^
Main.java:90: error: ';' expected
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
                                                                                   ^
Main.java:92: error: illegal start of expression
    const std::vector<Direction> directions = { Direction::North, Direction::East, Direction::South, Direction::West };
    ^
Main.java:92: error: illegal start of expression
    const std::vector<Direction> directions = { Direction::North, Direction::East, Direction::South, Direction::West };
                                              ^
Main.java:92: error: not a statement
    const std::vector<Direction> directions = { Direction::North, Direction::East, Direction::South, Direction::West };
                                                ^
Main.java:92: error: ';' expected
    const std::vector<Direction> directions = { Direction::North, Direction::East, Direction::South, Direction::West };
                                                                ^
Main.java:92: error: not a statement
    const std::vector<Direction> directions = { Direction::North, Direction::East, Direction::South, Direction::West };
                                                                  ^
Main.java:92: error: ';' expected
    const std::vector<Direction> directions = { Direction::No