SRM 504 Div2 Easy ComparerInator

問題

整数aとbが与えられた時次の演算が出来る.
"a" : This program will return the given argument a.
"b" : This program will return the given argument b.
"a

解答

全ての入力に対してそれぞれ4つの演算が成り立つかどうかをチェック.

class ComparerInator {
public:
  int makeProgram(vector <int> A, vector <int> B, vector <int> wanted) {
    int res;
    int i;
    int n = A.size();
    vector<bool> flag(4, true);
    for(i = 0; i < n; i++){
      if(!(A[i] == wanted[i])) flag[0] = false;
      if(!(B[i] == wanted[i])) flag[1] = false;
      if(!((A[i]<B[i]?A[i]:B[i]) == wanted[i])) flag[2] = false;
      if(!((A[i]<B[i]?B[i]:A[i]) == wanted[i])) flag[3] = false;
    }
    if(flag[0] || flag[1]) return 1;
    if(flag[2] || flag[3]) return 7;
    return -1;
    return res;
  }
};