Language: C++

/*
    Converted from Scratch by scratch2cpp (https://github.com/yos1up/scratch2cpp).
*/
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#define debug cerr << "--" << __LINE__ << "--" << "\n"
typedef long long ll;
using namespace std;

class Var{ // NOTE: immutable
public:
    mutable string sval;
    mutable long double dval;
    enum NumericState {UNKNOWN = -1, STRINGY = 0, NUMERIC = 1};
    mutable NumericState numericState;
    mutable bool svalValid, dvalValid; // TODO: initialize at here?

    Var(){
        *this = Var("");
    }
    Var(string s){
        sval = s;
        svalValid = true; dvalValid = false;
        numericState = UNKNOWN;
    }
    Var(long double d){
        dval = d;
        svalValid = false; dvalValid = true;
        numericState = NUMERIC;
    }
    Var(const Var &v){
        sval = string(v.sval); dval = v.dval;
        svalValid = v.svalValid; dvalValid = v.dvalValid;
        numericState = v.numericState;
    }
    void fillDval() const{
        if (dvalValid) return;
        long double d;
        bool numeric = isNumericString(sval, &d);
        if (numeric){
            numericState = NUMERIC;
            dval = d;
        }else{
            numericState = STRINGY;
            dval = 0.0;
        }        
        dvalValid = true;
    }
    static bool isNumericString(const string &s, long double *ptr) {
        char* ep;
        // cause side-effect: errno can be ERANGE after calling strtod
        *ptr = strtold(s.c_str(), &ep);
        // Scratch 3.0 recognize the string cause underflows or overflows as Numeric
        return NULL != ep && '\0' == ep[0] && s[0] != '\0';
    }
    bool isNumeric() const{
        fillDval();
        return numericState == NUMERIC;
    }    
    void fillSval() const{
        if (svalValid) return;
        sval = (floorl(dval) == dval) ? to_string((ll)dval) : to_string(dval);
        svalValid = true;
    }       
    long double asNumber() const{
        fillDval();
        return dval;
    } 
    string asString() const{
        fillSval();
        return sval;
    }
    Var operator+(const Var &y) const{
        return Var(this->asNumber() + y.asNumber());
    }
    Var operator+=(const Var &y){
        *this = *this + y;
        return *this;
    }
    Var operator-(const Var &y) const{
        return Var(this->asNumber() - y.asNumber());
    }
    Var operator*(const Var &y) const{
        return Var(this->asNumber() * y.asNumber());
    }
    Var operator/(const Var &y) const{
        return Var(this->asNumber() / y.asNumber());
    }
    Var operator%(const Var &y) const{
        return Var(fmodl(this->asNumber(), y.asNumber()));
    }
    bool operator<(const Var &y) const{
        if (this->isNumeric() && y.isNumeric()){
            return this->asNumber() < y.asNumber();
        } // compare as number if both can be interpreted as numeric
        return this->asString() < y.asString();
    }
    bool operator>(const Var &y) const{
        return y < *this;
    }
    bool operator==(const Var &y) const{
        if (this->isNumeric() && y.isNumeric()){
            return this->asNumber() == y.asNumber();
        } // compare as numeric if both are numeric
        return this->asString() == y.asString();
    }
    friend ostream& operator << (ostream& os, const Var& p);
    friend istream& operator >> (istream& is, const Var& p);
};
ostream& operator << (ostream& os, const Var& p){
    os << p.asString();
    return os;
}
istream& operator >> (istream& is, Var& p){
    string s; is >> s; p = Var(s);
    return is;
}


Var letterOf(Var index, Var sourceString){
    /* index: 1-origined */
    string str = sourceString.asString();
    int idx = (int)(index.asNumber() - 1);
    // seem to be dirty but Scratch seems to do like this.
    // ex. letterOf(0.01, "world") == "w", letterOf(1.99, "world") == "w", letterOf(5.99, "world") == "d"
    if (0 <= idx && idx < str.size()) return Var(str.substr(idx, 1));
    return Var();
}

class VarList{
public:
    vector<Var> data;
    VarList(const vector<Var> &x) { data = x; }
    void push_back(const Var &x){ data.push_back(x); }
    void pop_back(){ data.pop_back(); }
    void clear(){ data.clear(); }
    int size(){ return (int) data.size(); }
    Var getLineOfList(const Var &index) const{
        /* index: 1-origined */
        int idx = (int)index.asNumber() - 1;
        // (unlike 'letterOf', index==0.9 does not work.)
        if (0 <= idx && idx < data.size()) return data[idx];
        return Var();
    }
    void setLineOfListTo(const Var &index, const Var &v){
        /* index: 1-origined */
        int idx = (int)index.asNumber() - 1;
        if (0 <= idx && idx < data.size()) data[idx] = v;
    }
    void deleteLineOfList(const Var &index){
        /* index: 1-origined */
        string kwd = index.asString();
        if (kwd == "all"){
            data.clear();
        }else if (kwd == "last"){
            data.pop_back();
        }else{
            int idx = (int)index.asNumber() - 1;
            if (0 <= idx && idx < data.size()) data.erase(data.begin() + idx);
        }
    }
    void insertAtIndexOfList(const Var &item, const Var &index){
        /* index: 1-origined */
        int idx = (int)index.asNumber() - 1;
        if (0 <= idx && idx <= data.size()) data.insert(data.begin() + idx, item);   
    }
    void insertAtRandomOfList(const Var &item){
        int idx = rand() % (data.size() + 1);
        data.insert(data.begin() + idx, item);
    }
    string asString() const{
        /* concatenate elements of list with space */
        // TODO: concatenated without spaces only if all elements are single characters.
        // (Is it an official bug? (or feature?))
        string ret;
        for(int i=0;i<data.size();i++){
            if (i > 0) ret += ' ';
            ret += data[i].asString();
        }
        return ret;        
    }
    int itemNumOfList(const Var &item) const{
        auto itr = find(data.begin(), data.end(), item);
        if (itr == data.end()) return 0;
        return 1 + (int)(itr - data.begin());
        /* index: 1-origined */
    }
    friend ostream& operator << (ostream& os, const VarList& p);
};
ostream& operator << (ostream& os, const VarList& p){
    os << p.asString();
    return os;
}

long double randUniform(const long double x, const long double y){
    if (x > y) return randUniform(y, x);
    if (floor(x) == x && floor(y) == y){
        ll xi = (ll)round(x), yi = (ll)round(y);
        return xi + rand() % (yi - xi + 1);
    }else{
        return x + (y - x) * (0.0 + rand()) / RAND_MAX;
    }
}

Var buf_answer; // for "answer"

// ============================= Scripts =============================

// variable declaration
Var var_N(8);
Var var_i(3);

// list declaration
VarList list_card({Var("true"), Var(2), Var(3), Var(4), Var("true"), Var(6), Var(7), Var(8), Var("true")});

// prototype declaration of functions
int main();
int func_find(const Var &arg_num);
int func_checkFinish();
int func_isMatched(const Var &arg_num, const Var &arg_num2, const Var &arg_num3);

// contents of functions
int main(){
    list_card.clear();
    for (int cnt_0=0;cnt_0<Var(9).asNumber();cnt_0++){
        cin >> buf_answer;
        list_card.push_back(buf_answer);
    }
    cin >> buf_answer;
    for (int cnt_1=0;cnt_1<var_N.asNumber();cnt_1++){
        cin >> buf_answer;
        func_find(buf_answer);
        func_checkFinish();
    }
    cout << Var("No") << endl;
    return 0;
    return 0;
}

int func_find(const Var &arg_num){
    var_i = Var(1);
    for (int cnt_2=0;cnt_2<Var(9).asNumber();cnt_2++){
        if ((list_card.getLineOfList(var_i) == arg_num)){
            list_card.setLineOfListTo(var_i, Var("true"));
        }
        var_i += Var(1);
    }
    return 0;
}

int func_checkFinish(){
    var_i = Var(0);
    for (int cnt_3=0;cnt_3<Var(3).asNumber();cnt_3++){
        func_isMatched((Var(1) + var_i), (Var(2) + var_i), (Var(3) + var_i));
        var_i += Var(3);
    }
    var_i = Var(0);
    for (int cnt_4=0;cnt_4<Var(3).asNumber();cnt_4++){
        func_isMatched((Var(1) + var_i), (Var(4) + var_i), (Var(7) + var_i));
        var_i += Var(1);
    }
    func_isMatched(Var(1), Var(5), Var(9));
    func_isMatched(Var(7), Var(5), Var(3));
    return 0;
}

int func_isMatched(const Var &arg_num, const Var &arg_num2, const Var &arg_num3){
    if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
        cout << Var("Yes") << endl;
        return 0;
    }
    return 0;
}

                                                                                     

Compiler output:
a.cc: In function 'int func_isMatched(const Var&, const Var&, const Var&)':
a.cc:272:83: error: no match for 'operator==' (operand types are 'bool' and 'Var')
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                             |                                                               |
      |                                             bool                                                            Var
In file included from /usr/include/c++/14/iosfwd:42,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/usr/include/c++/14/bits/postypes.h:192:5: note: candidate: 'template<class _StateT> bool std::operator==(const fpos<_StateT>&, const fpos<_StateT>&)'
  192 |     operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/postypes.h:192:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::fpos<_StateT>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/bits/allocator.h:235:5: note: candidate: 'template<class _T1, class _T2> bool std::operator==(const allocator<_CharT>&, const allocator<_T2>&)'
  235 |     operator==(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/14/bits/allocator.h:235:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::allocator<_CharT>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:441:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  441 |     operator==(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:441:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
/usr/include/c++/14/bits/stl_iterator.h:486:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  486 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:486:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1667 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1737 |     operator==(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/stl_pair.h:1033:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1033 |     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1033:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::pair<_T1, _T2>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54:
/usr/include/c++/14/string_view:629:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator==(basic_string_view<_CharT, _Traits>, __type_identity_t<basic_string_view<_CharT, _Traits> >)'
  629 |     operator==(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:629:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'std::basic_string_view<_CharT, _Traits>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
/usr/include/c++/14/string_view:637:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator==(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  637 |     operator==(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:637:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'std::basic_string_view<_CharT, _Traits>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
/usr/include/c++/14/string_view:644:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator==(__type_identity_t<basic_string_view<_CharT, _Traits> >, basic_string_view<_CharT, _Traits>)'
  644 |     operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:644:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   'Var' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
/usr/include/c++/14/bits/basic_string.h:3755:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3755 |     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3755:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'bool'
  272 |     if ((((list_card.getLineOfList(arg_num) == list_card.getLineOfList(arg_num2)) == list_card.getLineOfList(arg_num3)) == Var("true"))){
      |                                                                                                                      ^
/usr/include/c++/14/bits/basic_string.h:3772:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3772 |     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3772:5: note:   template argument deduction/substitution failed:
a.cc:272:118: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'b