criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<iostream>
#include<string.h>
#define MAX 300001

using namespace std;

bool prime[MAX];

int main(void){
	
	int n,p,num;
	
	p=0;
	memset(prime,true,sizeof(prime));
	
	for(int i=0;i<6;i++){
		prime[i]=false;
	}
	
	for(int i=2;i<=MAX;i++){
		for(int j=6*i;j<=MAX;j++){
			if(prime[i]){
				prime[j]=false;
			}	
		}
	}
	
	while(cin>>n){
		if(n==1){
			break;
		}
		cout<<n<<": ";
		for(int i=0;i<n;i++){
			if(prime[i]==true && 0==(n%prime[i]){
					cout<<prime[i]<<" ";
			}
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:61: error: expected ')' before '{' token
   34 |                         if(prime[i]==true && 0==(n%prime[i]){
      |                           ~                                 ^
      |                                                             )
a.cc:37:17: error: expected primary-expression before '}' token
   37 |                 }
      |                 ^
Language: C++

#include<iostream>
#include<string.h>
#define MAX 300001

using namespace std;

bool prime[MAX];
int table[MAX];

int main(void){
	
	int n,p,num;
	
	p=0;
	memset(prime,true,sizeof(prime));
	memset(table,0,sizeof(table));
	
	for(int i=0;i<6;i++){
		prime[i]=false;
	}
	
	for(int i=6;i<=MAX;i++){
		for(int j=6*i;j<=MAX;j++){
			if(prime[i]){
				table[p++]=i;
				prime[j]=false;
			}	
		}
	}
	
	while(1){
		cin>>n;
		if(n==1){
			break;
		}
		cout<<n<<": ";
		for(int i=0;i<p;i++){
				if(0==(n%table[i])){
					cout<<table[i]<<" ";
				}
			}
		}
		cout<<endl;
	}
}

Compiler output:
a.cc:45:1: error: expected declaration before '}' token
   45 | }
      | ^
Language: C++

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <ctype.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef  vector< vector<int> > vector2d;


string IntToString(int number)
{
  string stream ss;
  ss << number;
  return ss.str();
}

int main (){

  int i,j,n;
  vector<int> prime;
  
  string temp;
  n = 10000;
  temp = n+'0';
  cout << temp <<endl;

  int judge[300000]={};

  for(i=1;i<42857;i++){
    judge[i*7+1] = 1;
    judge[i*7+6] = 1;
  }
  
  //素数リスト作成
  for(i=8;i<300000;i++){
    if (judge[i]==1){
      prime.push_back(i);
      for(j=2;j<300000/i;j++){
	judge[j*i]=0;
      }
    }
  }
  
  while(1){
    cin >> n;
    if (n==1)break;
    
    cout << "bb" <<endl;
    
    string ans;
    ans = IntToString(n) + ":";
    
    //cout << ans <<endl;
    
    for(i=0;n!=1;i++){
      if(n%prime[i]==0){
        ans += " " + IntToString(prime[i]);
	n = n / prime[i];
      }
    }
    
    cout << ans << endl;
    
  }
  
  return 0;
}

Compiler output:
a.cc: In function 'std::string IntToString(int)':
a.cc:14:17: error: expected initializer before 'ss'
   14 |   string stream ss;
      |                 ^~
a.cc:15:3: error: 'ss' was not declared in this scope
   15 |   ss << number;
      |   ^~
Language: C++

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <ctype.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef  vector< vector<int> > vector2d;


string IntToString(int number)
{
  stringstream ss;
  ss << number;
  return ss.str();
}

int main (){

  int i,j,n;
  vector<int> prime;
  s
  int judge[300000]={};

  for(i=1;i<42857;i++){
    judge[i*7+1] = 1;
    judge[i*7+6] = 1;
  }
  
  //素数リスト作成
  for(i=8;i<300000;i++){
    if (judge[i]==1){
      prime.push_back(i);
      for(j=2;j<300000/i;j++){
	judge[j*i]=0;
      }
    }
  }
  
  while(1){
    cin >> n;
    if (n==1)break;
    
    cout << "bb" <<endl;
    
    string ans;
    ans = IntToString(n) + ":";
    
    //cout << ans <<endl;
    
    for(i=0;n!=1;i++){
      if(n%prime[i]==0){
        ans += " " + IntToString(prime[i]);
	n = n / prime[i];
      }
    }
    
    cout << ans << endl;
    
  }
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:3: error: 's' was not declared in this scope
   23 |   s
      |   ^
a.cc:27:5: error: 'judge' was not declared in this scope
   27 |     judge[i*7+1] = 1;
      |     ^~~~~
a.cc:33:9: error: 'judge' was not declared in this scope
   33 |     if (judge[i]==1){
      |         ^~~~~
Language: Java

import java.util.Scanner;

public class Main1 {

	static char[] s;
	static char[] var;
	static int[] PQR;
	static int[] tuf = {0, 1, 2};// true, unknown, false
	static int idx;
	static int varCount;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			varCount=idx=0;
			String str = cin.next();
			if(str.equals(".")){
				break;
			}
			s = new char[80];
			var = new char[80];
			PQR=new int[3];
			for(int i = 0; i < str.length(); i++){
				char c = str.charAt(i);
				if(c == '-' || c == '*' || c == '+' || c == '(' || c == ')'){
					s[idx++]=c;
				}
				else if(c=='P'){
					var[varCount++]=0;
				}
				else if(c=='Q'){
					var[varCount++]=1;
				}
				else if(c=='R'){
					var[varCount++]=2;
				}
				else if(c=='0'){
					var[varCount++]=3;
				}
				else if(c=='1'){
					var[varCount++]=4;
				}
				else if(c=='2'){
					var[varCount++]=5;
				}
			}

			int count=0;
			for(int i = 0; i < 3; i++){
				for(int j = 0; j < 3; j++){
					for(int k = 0; k < 3; k++){
						varCount=idx=0;
						PQR[0]=tuf[i];
						PQR[1]=tuf[j];
						PQR[2]=tuf[k];
						if(expression()==2){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
	static int expression(){
		int res = term();
		if(s[idx]=='+'){
			idx++;
			res = or(res, expression());
		}
		return res;
	}
	static int term(){
		int res = fact();
		if(s[idx]=='*'){
			idx++;
			res = and(res, term());
		}
		return res;
	}
	static int fact(){
		int res;
		if(s[idx]=='('){
			idx++;
			res=expression();
			idx++;
		}
		else if(s[idx]=='-'){
			idx++;
			res = not(fact());
		}
		else{
			res = variable();
		}
		return res;
	}
	static int variable(){
		if(var[varCount]>=3){
			return var[varCount++]-3;
		}
		return PQR[var[varCount++]];
	}
	static int or(int x, int y){
		if(x <= 1 && y <= 1){
			if(x == 0 && y == 0){
				return 0;
			}
			else{
				return 1;
			}
		}
		else{
			return 2;
		}
		
	}
	static int and(int x, int y){
		if(x >= 1 && y >= 1){
			if(x == 2 && y == 2){
				return 2;
			}
			else{
				return 1;
			}
		}
		else{
			return 0;
		}
	}
	static int not(int x){
		if(x ==0){
			return 2;
		}
		else if(x==1){
			return 1;
		}
		else{
			return 0;
		}
	}
}

Compiler output:
Main.java:3: error: class Main1 is public, should be declared in a file named Main1.java
public class Main1 {
       ^
1 error
Language: Java

package p1155;


import java.util.Scanner;

public class Main3 {

	static char[] s;
	static int[] PQR;
	static int[] tuf = {0, 1, 2};// true, unknown, false
	static int idx;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			idx=0;
			String str = cin.next();
			if(str.equals(".")){
				break;
			}
			s = new char[81];
			PQR=new int[3];
			for(int i = 0; i < str.length(); i++){
				s[i] = str.charAt(i);
			}

			int count=0;
			for(int i = 0; i < 3; i++){
				for(int j = 0; j < 3; j++){
					for(int k = 0; k < 3; k++){
						idx=0;
						PQR[0]=tuf[i];
						PQR[1]=tuf[j];
						PQR[2]=tuf[k];
						if(expression()==2){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
	static int expression(){
		int res = term();
		if(s[idx]=='+'){
			idx++;
			res = or(res, expression());
		}
		return res;
	}
	static int term(){
		int res = fact();
		if(s[idx]=='*'){
			idx++;
			res = and(res, term());
		}
		return res;
	}
	static int fact(){
		int res;
		if(s[idx]=='('){
			idx++;
			res=expression();
			idx++;
		}
		else if(s[idx]=='-'){
			idx++;
			res = not(fact());
		}
		else{
			res = variable();
		}
		return res;
	}
	static int variable(){
		if(s[idx]=='P'){
			idx++;
			return PQR[0];
		}
		else if(s[idx]=='Q'){
			idx++;
			return PQR[1];
		}
		else if(s[idx]=='R'){
			idx++;
			return PQR[2];
		}
		else{
			return s[idx++] - '0';
		}
	}
	static int or(int x, int y){
		if(x <= 1 && y <= 1){
			if(x == 0 && y == 0){
				return 0;
			}
			else{
				return 1;
			}
		}
		else{
			return 2;
		}
		
	}
	static int and(int x, int y){
		if(x >= 1 && y >= 1){
			if(x == 2 && y == 2){
				return 2;
			}
			else{
				return 1;
			}
		}
		else{
			return 0;
		}
	}
	static int not(int x){
		if(x ==0){
			return 2;
		}
		else if(x==1){
			return 1;
		}
		else{
			return 0;
		}
	}
}

Compiler output:
Main.java:6: error: class Main3 is public, should be declared in a file named Main3.java
public class Main3 {
       ^
1 error
Language: C

#define M(x,y)(x>y?x:y)
#define m(x,y)(x<y?x:y)
I;int parse(char *p){switch(*p){
	case'0':return 0;
	case'1':return 1;
	case'2':return 2;
	case'P':return I%3;
	case'Q':return I/3%3;
	case'R':return I/9%3;
	case'-':return 2-parse(p+1);
	case'(':{
		int x=0;
		char*q=++p;
		for(;;p++){
			if(*p=='(')x++;
			if(*p==')')x--;
			if(x==0&&*p!='-')break;
		}
		return (*(++p)=='*')?m(parse(q),parse(p+1)):M(parse(q),parse(p+1));
	}
}
char p[81];main(s){for(;scanf("%s",p),*p-'.';printf("%d\n",s))for(s=I=0;I<27;I++)s+=parse(p)==2;exit(0);}

Compiler output:
main.c:3:1: warning: data definition has no type or storage class
    3 | I;int parse(char *p){switch(*p){
      | ^
main.c:3:1: error: type defaults to 'int' in declaration of 'I' [-Wimplicit-int]
main.c: In function 'parse':
main.c:22:6: error: 'p' redeclared as different kind of symbol
   22 | char p[81];main(s){for(;scanf("%s",p),*p-'.';printf("%d\n",s))for(s=I=0;I<27;I++)s+=parse(p)==2;exit(0);}
      |      ^
main.c:3:19: note: previous definition of 'p' with type 'char *'
    3 | I;int parse(char *p){switch(*p){
      |             ~~~~~~^
main.c:22:12: error: implicit declaration of function 'main' [-Wimplicit-function-declaration]
   22 | char p[81];main(s){for(;scanf("%s",p),*p-'.';printf("%d\n",s))for(s=I=0;I<27;I++)s+=parse(p)==2;exit(0);}
      |            ^~~~
main.c:22:17: error: 's' undeclared (first use in this function)
   22 | char p[81];main(s){for(;scanf("%s",p),*p-'.';printf("%d\n",s))for(s=I=0;I<27;I++)s+=parse(p)==2;exit(0);}
      |                 ^
main.c:22:17: note: each undeclared identifier is reported only once for each function it appears in
main.c:22:19: error: expected ';' before '{' token
   22 | char p[81];main(s){for(;scanf("%s",p),*p-'.';printf("%d\n",s))for(s=I=0;I<27;I++)s+=parse(p)==2;exit(0);}
      |                   ^
      |                   ;
main.c:22:1: error: expected declaration or statement at end of input
   22 | char p[81];main(s){for(;scanf("%s",p),*p-'.';printf("%d\n",s))for(s=I=0;I<27;I++)s+=parse(p)==2;exit(0);}
      | ^~~~
Language: C++

#include<iostream>
#include<string>
#include<cctype>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long Int;
typedef string::const_iterator Itr;

int P, Q, R;

int expression(Itr &itr);
int term(Itr &itr);
int factor(Itr &itr);
int letter(Itr &itr);

int not(int n)
{
	if (n == 0)return 2;
	else if (n == 1)return 1;
	else return 0;
}

int star(int x, int y)
{
	if (x == 0 || y == 0)return 0;
	else if (x == 1 || y == 1)return 1;
	else return 2;
}

int _plus(int x, int y)
{
	if (x == 0 && y == 0)return 0;
	else if (x == 2 || y == 2)return 2;
	else return 1;
}

int expression(Itr &itr) 
{
	int ret = term(itr);

	while (true)
	{
		if (*itr == '*')
		{
			itr++;
			ret = star(ret, term(itr));

		}
		else if (*itr == '+')
		{
			itr++;
			ret = _plus(ret, term(itr));
		}
		else
		{
			break;
		}
	}
	return ret;
}

int term(Itr &itr)
{
	int ret;

	if (*itr == '-')
	{
		itr++;
		ret = not(term(itr));
	}
	else
	{
		ret = factor(itr);
	}

	return ret;
}

int factor(Itr &itr)
{
	int ret;

	if (*itr == '(')
	{
		itr++;
		ret = expression(itr);
		itr++;
	}
	else
	{
		ret = letter(itr);
	}

	return ret;
}

int letter(Itr &itr)
{
	int ret = 0;

	if (*itr == 'P')
	{
		ret = P;
	}
	else if (*itr == 'Q')
	{
		ret = Q;
	}
	else if (*itr == 'R')
	{
		ret = R;
	}
	else if(isdigit(*itr))
	{
		ret = *itr - '0';
	}
	itr++;
	return ret;
}

int main()
{
	while (true)
	{
		string str;
		getline(cin, str);
		if (str[0] == '.')break;
		str.append("_");
		int count = 0;
		REP(i, 3)REP(j, 3)REP(k, 3)
		{
			P = i;
			Q = j;
			R = k;
			Itr begin = str.begin();
			int ans = expression(begin);
			if (ans == 2)
			{
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}


Compiler output:
a.cc:16:5: error: expected unqualified-id before 'not' token
   16 | int not(int n)
      |     ^~~
Language: C++

#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef vector<int> vi;
const int MAX_V=1e3+5;
const int INF=1e9;
vector< vector<int> > board(25,vector<int>(25,0) );
int w,h;
int sy,sx,gy,gx;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int goal=100;
//Prototype
int expr(string& s, int& i);
int term(string& s, int& i);
int factor(string& s, int& i);
int number(string& s, int& i);


int number(string &s,int &i)
{
  int n=s[i++]-'0';
  while(isdigit(s[i])) n=n*10+s[i++]-'0';
  return n;
}

int factor(string &s,int &i)
{
  if(isdigit(s[i])) return number(s,i);
  assert(s[i]=='(');
  i++;
  int ret=expr(s,i);
  i++;
  return ret;
}
int term(string &s, int &i)
{
  int val;
  if(s[i]!='-')
    {
      val=factor(s,i);
    }
  while(s[i]=='-')
    {
      i++;
      int val2=term(s,i);
      if(val2==0) val=2;
      if(val2==1) val=1;
      if(val2==2) val=0;
    }
  return val;
}
int expr(string &s, int &i)
{
  int val=term(s,i);
  while(s[i]=='*' || s[i]=='+')
    {
      char op=s[i];
      i++;
      int val2=term(s,i);
      if(op=='*') val=min(val,val2);
      else if(op=='+') val=max(val,val2); 
    }
  return val;
}
int main(void)
{
  string s;
  while(cin >> s && s!=".")
    {
      int ans=0;
      string origin=s;
      for(int r=0;r<=2;r++)
	{
	  for(int p=0;p<=2;p++)
	    {
	      for(int q=0;q<=2;q++)
		{
		  s=origin;
		  for(int i=0;i<int(s.size());i++)
		    {
		      if(s[i]=='P') s[i]='0'+p;
		      if(s[i]=='Q') s[i]='0'+q;
		      if(s[i]=='R') s[i]='0'+r;
		    }
		  //cout << s << endl;
		  int i=0;
		  if(expr(s,i)==2) ans++;
		}
	    }
	}
      cout << ans << endl;
    }
  return 0;
 
}



Compiler output:
a.cc: In function 'int factor(std::string&, int&)':
a.cc:35:3: error: 'assert' was not declared in this scope
   35 |   assert(s[i]=='(');
      |   ^~~~~~
a.cc:8:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    7 | #include<cmath>
  +++ |+#include <cassert>
    8 | using namespace std;
Language: C++

string in;
int pos;
int p,q,r;

int formula(){
  if(isdigit(in[pos])){
    return in[pos++]-'0';
  }

  switch(in[pos]){
  case 'P':++pos; return p;
  case 'Q':++pos; return q;
  case 'R':++pos; return r;
  }

  if(in[pos]=='-'){
    ++pos;
    return 2-formula();
  }
  ++pos;
  int a=formula();
  char cc=in[pos++];
  int b=formula();
  pos++;
  if(cc=='+'){
    if(a==2 || b==2)return 2;
    if(!a && !b)return 0;
    return 1;
  }
  if(!a || !b)return 0;
  if(a==2 && b==2)return 2;
  return 1;
}


main(){
  while(cin>>in){
    if(in==".")break;
    int ans=0;
    for(p=0;p<3;p++)for(q=0;q<3;q++)for(r=0;r<3;r++){
      pos=0;
      if(formula()==2)++ans;
    }
    cout<<ans<<endl;
  }
}

Compiler output:
a.cc:1:1: error: 'string' does not name a type
    1 | string in;
      | ^~~~~~
a.cc: In function 'int formula()':
a.cc:6:14: error: 'in' was not declared in this scope; did you mean 'int'?
    6 |   if(isdigit(in[pos])){
      |              ^~
      |              int
a.cc:6:6: error: 'isdigit' was not declared in this scope
    6 |   if(isdigit(in[pos])){
      |      ^~~~~~~
a.cc:10:10: error: 'in' was not declared in this scope; did you mean 'int'?
   10 |   switch(in[pos]){
      |          ^~
      |          int
a.cc:16:6: error: 'in' was not declared in this scope; did you mean 'int'?
   16 |   if(in[pos]=='-'){
      |      ^~
      |      int
a.cc:22:11: error: 'in' was not declared in this scope; did you mean 'int'?
   22 |   char cc=in[pos++];
      |           ^~
      |           int
a.cc: At global scope:
a.cc:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:37:9: error: 'cin' was not declared in this scope
   37 |   while(cin>>in){
      |         ^~~
a.cc:37:14: error: 'in' was not declared in this scope; did you mean 'int'?
   37 |   while(cin>>in){
      |              ^~
      |              int
a.cc:44:5: error: 'cout' was not declared in this scope
   44 |     cout<<ans<<endl;
      |     ^~~~
a.cc:44:16: error: 'endl' was not declared in this scope
   44 |     cout<<ans<<endl;
      |                ^~~~
Language: C++

#include<iostream>
#include<string>

string in;
int pos;
int p,q,r;

int formula(){
  if(isdigit(in[pos])){
    return in[pos++]-'0';
  }

  switch(in[pos]){
  case 'P':++pos; return p;
  case 'Q':++pos; return q;
  case 'R':++pos; return r;
  }

  if(in[pos]=='-'){
    ++pos;
    return 2-formula();
  }
  ++pos;
  int a=formula();
  char cc=in[pos++];
  int b=formula();
  pos++;
  if(cc=='+'){
    if(a==2 || b==2)return 2;
    if(!a && !b)return 0;
    return 1;
  }
  if(!a || !b)return 0;
  if(a==2 && b==2)return 2;
  return 1;
}


main(){
  while(cin>>in){
    if(in==".")break;
    int ans=0;
    for(p=0;p<3;p++)for(q=0;q<3;q++)for(r=0;r<3;r++){
      pos=0;
      if(formula()==2)++ans;
    }
    cout<<ans<<endl;
  }
}

Compiler output:
a.cc:4:1: error: 'string' does not name a type; did you mean 'stdin'?
    4 | string in;
      | ^~~~~~
      | stdin
a.cc: In function 'int formula()':
a.cc:9:14: error: 'in' was not declared in this scope; did you mean 'int'?
    9 |   if(isdigit(in[pos])){
      |              ^~
      |              int
a.cc:13:10: error: 'in' was not declared in this scope; did you mean 'int'?
   13 |   switch(in[pos]){
      |          ^~
      |          int
a.cc:19:6: error: 'in' was not declared in this scope; did you mean 'int'?
   19 |   if(in[pos]=='-'){
      |      ^~
      |      int
a.cc:25:11: error: 'in' was not declared in this scope; did you mean 'int'?
   25 |   char cc=in[pos++];
      |           ^~
      |           int
a.cc: At global scope:
a.cc:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:40:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   40 |   while(cin>>in){
      |         ^~~
      |         std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:40:14: error: 'in' was not declared in this scope; did you mean 'int'?
   40 |   while(cin>>in){
      |              ^~
      |              int
a.cc:47:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   47 |     cout<<ans<<endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:47:16: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   47 |     cout<<ans<<endl;
      |                ^~~~
      |                std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C++

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
//#include<>
using namespace std;

typedef long long ll;
#define rep(i,j) for(i=0;i<j;i++)
#define rev_rep(i,j) for(i=j;i>=0;i&#8212;-)

int not_[3]={2,1,0};
int and_[3][3]={{0,0,0},{0,1,1},{0,1,2}};
int or_[3][3]={{0,1,2},{1,1,2},{2,2,2}};

int i,p,q,r;
int rec(string s)
{
  stack<char>key;
  int ans=0,v;
  key.push('+');
  while(i<s.size())
    {
      if(s[i]==')')
	{return ans;}
      else if(s[i]=='+'||s[i]=='-'||s[i]=='*')
	  key.push(s[i++]);
      else
	{
	  if(s[i]=='(')
	    {i++;v=rec(s);}
	  else if(s[i]=='P')v=p;
	  else if(s[i]=='Q')v=q;
	  else if(s[i]=='R')v=r;
	  else
	      v=s[i]-'0';
	  while(!key.empty())
	    {
	      if(key.top()=='+')
		ans=or_[ans][v];
	      else if(key.top()=='-')
		{
		  v=not_[v];
		  if(key.size()==1)ans=v;
		}
	      else if(key.top()=='*')
		ans=and_[ans][v];
	      key.pop();
	    }
	  i++;
	}
    }
  return ans;
}

int main()
{
  string s;
  while(cin>>s)
    {
      if(s[0]=='.')return 0;
      int a,b,c;
      int cnt=0;
      rep(a,3)rep(b,3)rep(c,3)
	{
	  p=a;q=b;r=c;
	  i=0;
	  if(rec(s)==2)cnt++;
	}
      cout<<cnt<<endl;
    }
  return 0;
}

Compiler output:
a.cc:15:20: error: '#' is not followed by a macro parameter
   15 | #define rev_rep(i,j) for(i=j;i>=0;i&#8212;-)
      |                    ^
Language: C++

#include <iostream>
#include <string>
using namespace std;

int p, q, r, cursor;
string s;

int not(int a) {
	return 2 - a;
}

int and(int a, int b) {
	if(a == 0 || b == 0) return 0;
	if(a == 1 || b == 1) return 1;
	return 2;
}

int or(int a, int b) {
	if(a == 2 || b == 2) return 2;
	if(a == 1 || b == 1) return 1;
	return 0;
}

int f() {
	char c = s[cursor];
	cursor++;
	if(c == '0') return 0;
	if(c == '1') return 1;
	if(c == '2') return 2;
	if(c == 'P') return p;
	if(c == 'Q') return q;
	if(c == 'R') return r;
	if(c == '-') return not(f());
	if(c == '(') {
		int a = f();
		char op = s[cursor];
		cursor++;
		int b = f();
		cursor++;
		if(op == '*') {
			return and(a, b);
		}
		else {
			return or(a, b);
		}
	}
	return -1;
}

int main() {
	while(cin >> s, s[0] != '.') {
		int ans = 0;
		for(p = 0; p <= 2; p++) {
			for(q = 0; q <= 2; q++) {
				for(r = 0; r <= 2; r++) {
					cursor = 0;
					if(f() == 2) ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Compiler output:
a.cc:8:5: error: expected unqualified-id before 'not' token
    8 | int not(int a) {
      |     ^~~
a.cc:12:9: error: expected unqualified-id before 'int'
   12 | int and(int a, int b) {
      |         ^~~
a.cc:12:9: error: expected ')' before 'int'
   12 | int and(int a, int b) {
      |        ~^~~
      |         )
a.cc:18:5: error: expected unqualified-id before 'or' token
   18 | int or(int a, int b) {
      |     ^~
a.cc: In function 'int f()':
a.cc:41:35: error: expected identifier before '(' token
   41 |                         return and(a, b);
      |                                   ^
a.cc:41:35: error: expected ';' before '(' token
   41 |                         return and(a, b);
      |                                   ^
      |                                   ;
a.cc:44:32: error: expected primary-expression before 'or' token
   44 |                         return or(a, b);
      |                                ^~
Language: C++

#include <iostream>
#include <string>
using namespace std;

int p, q, r, cursor;
string s;

int Not(int a) {
	return 2 - a;
}

int and(int a, int b) {
	if(a == 0 || b == 0) return 0;
	if(a == 1 || b == 1) return 1;
	return 2;
}

int or(int a, int b) {
	if(a == 2 || b == 2) return 2;
	if(a == 1 || b == 1) return 1;
	return 0;
}

int f() {
	char c = s[cursor];
	cursor++;
	if(c == '0') return 0;
	if(c == '1') return 1;
	if(c == '2') return 2;
	if(c == 'P') return p;
	if(c == 'Q') return q;
	if(c == 'R') return r;
	if(c == '-') return Not(f());
	if(c == '(') {
		int a = f();
		char op = s[cursor];
		cursor++;
		int b = f();
		cursor++;
		if(op == '*') {
			return and(a, b);
		}
		else {
			return or(a, b);
		}
	}
	return -1;
}

int main() {
	while(cin >> s, s[0] != '.') {
		int ans = 0;
		for(p = 0; p <= 2; p++) {
			for(q = 0; q <= 2; q++) {
				for(r = 0; r <= 2; r++) {
					cursor = 0;
					if(f() == 2) ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Compiler output:
a.cc:12:9: error: expected unqualified-id before 'int'
   12 | int and(int a, int b) {
      |         ^~~
a.cc:12:9: error: expected ')' before 'int'
   12 | int and(int a, int b) {
      |        ~^~~
      |         )
a.cc:18:5: error: expected unqualified-id before 'or' token
   18 | int or(int a, int b) {
      |     ^~
a.cc: In function 'int f()':
a.cc:41:35: error: expected identifier before '(' token
   41 |                         return and(a, b);
      |                                   ^
a.cc:41:35: error: expected ';' before '(' token
   41 |                         return and(a, b);
      |                                   ^
      |                                   ;
a.cc:44:32: error: expected primary-expression before 'or' token
   44 |                         return or(a, b);
      |                                ^~
Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include <cctype>
#include <cassert>
using namespace std;

typedef int value;

string s;
size_t cur = 0;
value P, Q, R;
int ans = 0;

value formula();

value not(){
	assert(s[cur] == '-');
	cur++;
	return 2 - formula();
}
value and(value a, value b){
	return (a<b) ? a : b;
}
value or(value a, value b){
	return (a<b) ? b : a;
}
value formula(){
	value a, b, f;
	char op;
	switch (s[cur]){
	case ('0') :
	case ('1') :
	case ('2') :
			   f = s[cur] - '0';
		cur++;
		break;
	case ('P') :
		f = P;
		cur++;
		break;
	case ('Q') :
		f = Q;
		cur++;
		break;
	case ('R') :
		f = R;
		cur++;
		break;
	case ('-') :
		f = not();
		break;
	case ('(') :
		cur++;
		a = formula();
		assert(s[cur] == '*' || s[cur] == '+');
		op = s[cur];
		cur++;
		b = formula();
		f = (op == '*') ? and(a, b) : or(a, b);
		assert(s[cur] == ')');
		cur++;
		break;
	default:
		assert(false);
		break;
	}
	return f;
}
int main(){
	cin >> s;
	while (s != "."){
		for (P = 0; P <= 2; P++)
			for (Q = 0; Q <= 2; Q++)
				for (R = 0; R <= 2; R++){
					if (formula() == 2)ans++;
					cur = 0;
				}
		cout << ans << endl;
		ans = 0;
		cin >> s;
	}
	return 0;
}

Compiler output:
a.cc:17:7: error: expected unqualified-id before 'not' token
   17 | value not(){
      |       ^~~
a.cc:22:16: error: expected ')' before 'a'
   22 | value and(value a, value b){
      |          ~     ^~
      |                )
a.cc:25:7: error: expected unqualified-id before 'or' token
   25 | value or(value a, value b){
      |       ^~
a.cc: In function 'value formula()':
a.cc:51:25: error: expected primary-expression before ')' token
   51 |                 f = not();
      |                         ^
a.cc:60:38: error: expected identifier before '(' token
   60 |                 f = (op == '*') ? and(a, b) : or(a, b);
      |                                      ^
a.cc:60:38: error: expected ':' before '(' token
   60 |                 f = (op == '*') ? and(a, b) : or(a, b);
      |                                      ^
      |                                      :
Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include <cctype>
#include <cassert>
using namespace std;
 
typedef int value;
 
string s;
size_t cur = 0;
value P, Q, R;
int ans = 0;

value not();
value and(value a, value b);
value or(value a, value b);
value formula();
 
value not(){
    assert(s[cur] == '-');
    cur++;
    return 2 - formula();
}
value and(value a, value b){
    return (a<b) ? a : b;
}
value or(value a, value b){
    return (a<b) ? b : a;
}
value formula(){
    value a, b, f;
    char op;
    switch (s[cur]){
    case ('0') :
    case ('1') :
    case ('2') :
               f = s[cur] - '0';
        cur++;
        break;
    case ('P') :
        f = P;
        cur++;
        break;
    case ('Q') :
        f = Q;
        cur++;
        break;
    case ('R') :
        f = R;
        cur++;
        break;
    case ('-') :
        f = not();
        break;
    case ('(') :
        cur++;
        a = formula();
        assert(s[cur] == '*' || s[cur] == '+');
        op = s[cur];
        cur++;
        b = formula();
        f = (op == '*') ? and(a, b) : or(a, b);
        assert(s[cur] == ')');
        cur++;
        break;
    default:
        assert(false);
        break;
    }
    return f;
}
int main(){
    cin >> s;
    while (s != "."){
        for (P = 0; P <= 2; P++)
            for (Q = 0; Q <= 2; Q++)
                for (R = 0; R <= 2; R++){
                    if (formula() == 2)ans++;
                    cur = 0;
                }
        cout << ans << endl;
        ans = 0;
        cin >> s;
    }
    return 0;
}

Compiler output:
a.cc:15:7: error: expected unqualified-id before 'not' token
   15 | value not();
      |       ^~~
a.cc:16:16: error: expected ')' before 'a'
   16 | value and(value a, value b);
      |          ~     ^~
      |                )
a.cc:17:7: error: expected unqualified-id before 'or' token
   17 | value or(value a, value b);
      |       ^~
a.cc:20:7: error: expected unqualified-id before 'not' token
   20 | value not(){
      |       ^~~
a.cc:25:16: error: expected ')' before 'a'
   25 | value and(value a, value b){
      |          ~     ^~
      |                )
a.cc:28:7: error: expected unqualified-id before 'or' token
   28 | value or(value a, value b){
      |       ^~
a.cc: In function 'value formula()':
a.cc:54:17: error: expected primary-expression before ')' token
   54 |         f = not();
      |                 ^
a.cc:63:30: error: expected identifier before '(' token
   63 |         f = (op == '*') ? and(a, b) : or(a, b);
      |                              ^
a.cc:63:30: error: expected ':' before '(' token
   63 |         f = (op == '*') ? and(a, b) : or(a, b);
      |                              ^
      |                              :
Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include <cctype>
#include <cassert>
using namespace std;

typedef int value;

string s;
size_t cur = 0;
value P, Q, R;
int ans = 0;

value and(value a, value b){
	return (a<b) ? a : b;
}
value or(value a, value b){
	return (a<b) ? b : a;
}
value formula(){
	value a, b, f;
	char op;
	switch (s[cur]){
	case ('0') :
	case ('1') :
	case ('2') :
			   f = s[cur] - '0';
		cur++;
		break;
	case ('P') :
		f = P;
		cur++;
		break;
	case ('Q') :
		f = Q;
		cur++;
		break;
	case ('R') :
		f = R;
		cur++;
		break;
	case ('-') :
		f = 2 - formula();
		break;
	case ('(') :
		cur++;
		a = formula();
		assert(s[cur] == '*' || s[cur] == '+');
		op = s[cur];
		cur++;
		b = formula();
		f = (op == '*') ? and(a, b) : or(a, b);
		assert(s[cur] == ')');
		cur++;
		break;
	default:
		assert(false);
		break;
	}
	return f;
}
int main(){
	cin >> s;
	while (s != "."){
		for (P = 0; P <= 2; P++)
			for (Q = 0; Q <= 2; Q++)
				for (R = 0; R <= 2; R++){
					if (formula() == 2)ans++;
					cur = 0;
				}
		cout << ans << endl;
		ans = 0;
		cin >> s;
	}
	return 0;
}

Compiler output:
a.cc:15:16: error: expected ')' before 'a'
   15 | value and(value a, value b){
      |          ~     ^~
      |                )
a.cc:18:7: error: expected unqualified-id before 'or' token
   18 | value or(value a, value b){
      |       ^~
a.cc: In function 'value formula()':
a.cc:53:38: error: expected identifier before '(' token
   53 |                 f = (op == '*') ? and(a, b) : or(a, b);
      |                                      ^
a.cc:53:38: error: expected ':' before '(' token
   53 |                 f = (op == '*') ? and(a, b) : or(a, b);
      |                                      ^
      |                                      :
Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include <cctype>
#include <cassert>
using namespace std;
 
typedef int value;
 
string s;
size_t cur = 0;
value P, Q, R;
int ans = 0;
 
static value and(value a, value b){
    return (a<b) ? a : b;
}
static value or(value a, value b){
    return (a<b) ? b : a;
}
value formula(){
    value a, b, f;
    char op;
    switch (s[cur]){
    case ('0') :
    case ('1') :
    case ('2') :
               f = s[cur] - '0';
        cur++;
        break;
    case ('P') :
        f = P;
        cur++;
        break;
    case ('Q') :
        f = Q;
        cur++;
        break;
    case ('R') :
        f = R;
        cur++;
        break;
    case ('-') :
        f = 2 - formula();
        break;
    case ('(') :
        cur++;
        a = formula();
        assert(s[cur] == '*' || s[cur] == '+');
        op = s[cur];
        cur++;
        b = formula();
        f = (op == '*') ? and(a, b) : or(a, b);
        assert(s[cur] == ')');
        cur++;
        break;
    default:
        assert(false);
        break;
    }
    return f;
}
int main(){
    cin >> s;
    while (s != "."){
        for (P = 0; P <= 2; P++)
            for (Q = 0; Q <= 2; Q++)
                for (R = 0; R <= 2; R++){
                    if (formula() == 2)ans++;
                    cur = 0;
                }
        cout << ans << endl;
        ans = 0;
        cin >> s;
    }
    return 0;
}

Compiler output:
a.cc:15:23: error: expected ')' before 'a'
   15 | static value and(value a, value b){
      |                 ~     ^~
      |                       )
a.cc:18:14: error: expected unqualified-id before 'or' token
   18 | static value or(value a, value b){
      |              ^~
a.cc: In function 'value formula()':
a.cc:53:30: error: expected identifier before '(' token
   53 |         f = (op == '*') ? and(a, b) : or(a, b);
      |                              ^
a.cc:53:30: error: expected ':' before '(' token
   53 |         f = (op == '*') ? and(a, b) : or(a, b);
      |                              ^
      |                              :
Language: C++

#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
const int wa[3][3]{
	{0,1,2},
	{1,1,2},
	{2,2,2}
};
const int se[3][3]{
	{0,0,0},
	{0,1,1},
	{0,1,2}
};
int calc(string& s, int &idx);
int brac(string& s, int &idx);
int num(string& s, int &idx);
int calc(string& s, int &idx) {
	int val1 = brac(s, idx);
	while (s[idx] == '*' || s[idx] == '+') {
		idx++;
		if (s[idx - 1] == '+') {
			int val2 = brac(s, idx);
			val1 = wa[val1][val2];
		}
		else {
			int val2 = brac(s, idx);
			val1 = se[val1][val2];
		}
	}
	return val1;
}
int brac(string& s, int &idx) {
	if (isdigit(s[idx])||s[idx]=='-')return num(s, idx);
	idx++;
	int val=calc(s, idx);
	idx++;
	return val;
}
int num(string& s, int &idx) {
	int not= 0;
	while (s[idx]=='-')
	{
		not++;
		idx++;
	}
	int val = s[idx] - '0';
	idx++;
	if (not% 2 == 1)
		if (val == 0)
			val = 2;
		else if (val == 2)
			val = 0;
	return val;
}
int main() {
	string s;
	while (cin >> s,s!=".") {
		int ans = 0;
		REP(i,3) {
			REP(j,3) {
				REP(k,3) {
					string s2 = s;
					replace(s2.begin(), s2.end(), 'P',(char)('0'+i) );
					replace(s2.begin(), s2.end(), 'Q', (char)('0' + j));
					replace(s2.begin(), s2.end(), 'R', (char)('0' + k));
					int num = 0;
					if (calc(s2,num) == 2)
						ans++;
				}
			}
		}
		cout <<ans<< endl;
	}
}

Compiler output:
a.cc: In function 'int num(std::string&, int&)':
a.cc:88:13: error: expected unqualified-id before 'not' token
   88 |         int not= 0;
      |             ^~~
a.cc:91:22: error: expected primary-expression before ';' token
   91 |                 not++;
      |                      ^
a.cc:96:16: error: expected primary-expression before '%' token
   96 |         if (not% 2 == 1)
      |                ^
Language: C++

#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
const int wa[3][3]{
	{0,1,2},
	{1,1,2},
	{2,2,2}
};
const int se[3][3]{
	{0,0,0},
	{0,1,1},
	{0,1,2}
};
int calc(string& s, int &idx);
int brac(string& s, int &idx);
int num(string& s, int &idx);
int calc(string& s, int &idx) {
	int val1 = brac(s, idx);
	while (s[idx] == '*' || s[idx] == '+') {
		idx++;
		if (s[idx - 1] == '+') {
			int val2 = brac(s, idx);
			val1 = wa[val1][val2];
		}
		else {
			int val2 = brac(s, idx);
			val1 = se[val1][val2];
		}
	}
	return val1;
}
int brac(string& s, int &idx) {
	if (isdigit(s[idx]) || s[idx]=='-')
		return number(s, idx);
	idx++;
	int val=calc(s, idx);
	idx++;
	return val;
}
int number(string& s, int &idx) {
	int not= 0;
	while (s[idx]=='-')
	{
		not++;
		idx++;
	}
	int val = s[idx] - '0';
	idx++;
	if (not% 2 == 1)
		if (val == 0)
			val = 2;
		else if (val == 2)
			val = 0;
	return val;
}
int main() {
	string s;
	while (cin >> s,s!=".") {
		int ans = 0;
		REP(i,3) {
			REP(j,3) {
				REP(k,3) {
					string s2 = s;
					replace(s2.begin(), s2.end(), 'P',(char)('0'+i) );
					replace(s2.begin(), s2.end(), 'Q', (char)('0' + j));
					replace(s2.begin(), s2.end(), 'R', (char)('0' + k));
					int num = 0;
					if (calc(s2,num) == 2)
						ans++;
				}
			}
		}
		cout <<ans<< endl;
	}
}

Compiler output:
a.cc: In function 'int brac(std::string&, int&)':
a.cc:82:24: error: 'number' was not declared in this scope
   82 |                 return number(s, idx);
      |                        ^~~~~~
a.cc: In function 'int number(std::string&, int&)':
a.cc:89:13: error: expected unqualified-id before 'not' token
   89 |         int not= 0;
      |             ^~~
a.cc:92:22: error: expected primary-expression before ';' token
   92 |                 not++;
      |                      ^
a.cc:97:16: error: expected primary-expression before '%' token
   97 |         if (not% 2 == 1)
      |                ^
Language: C++

#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
const int wa[3][3]{
	{0,1,2},
	{1,1,2},
	{2,2,2}
};
const int se[3][3]{
	{0,0,0},
	{0,1,1},
	{0,1,2}
};
int calc(string& s, int &idx);
int brac(string& s, int &idx);
int number(string& s, int &idx);
int calc(string& s, int &idx) {
	int val1 = brac(s, idx);
	while (s[idx] == '*' || s[idx] == '+') {
		idx++;
		if (s[idx - 1] == '+') {
			int val2 = brac(s, idx);
			val1 = wa[val1][val2];
		}
		else {
			int val2 = brac(s, idx);
			val1 = se[val1][val2];
		}
	}
	return val1;
}
int brac(string& s, int &idx) {
	if (isdigit(s[idx]) || s[idx]=='-')
		return number(s, idx);
	idx++;
	int val=calc(s, idx);
	idx++;
	return val;
}
int number(string& s, int &idx) {
	int not= 0;
	while (s[idx]=='-')
	{
		not++;
		idx++;
	}
	int val = s[idx] - '0';
	idx++;
	if (not% 2 == 1)
		if (val == 0)
			val = 2;
		else if (val == 2)
			val = 0;
	return val;
}
int main() {
	string s;
	while (cin >> s,s!=".") {
		int ans = 0;
		REP(i,3) {
			REP(j,3) {
				REP(k,3) {
					string s2 = s;
					replace(s2.begin(), s2.end(), 'P',(char)('0'+i) );
					replace(s2.begin(), s2.end(), 'Q', (char)('0' + j));
					replace(s2.begin(), s2.end(), 'R', (char)('0' + k));
					int num = 0;
					if (calc(s2,num) == 2)
						ans++;
				}
			}
		}
		cout <<ans<< endl;
	}
}

Compiler output:
a.cc: In function 'int number(std::string&, int&)':
a.cc:89:13: error: expected unqualified-id before 'not' token
   89 |         int not= 0;
      |             ^~~
a.cc:92:22: error: expected primary-expression before ';' token
   92 |                 not++;
      |                      ^
a.cc:97:16: error: expected primary-expression before '%' token
   97 |         if (not% 2 == 1)
      |                ^
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define MAX_N 100

using namespace std;

char form[MAX_N];
char str[MAX_N];

int calc_form(int l, int r){ //l-r???????????????????¨????
	int former, latter;
	int count = 0;
	int i;
	if(str[l] == '0') return 0;
	if(str[l] == '1') return 1;
	if(str[l] == '2') return 2;
	if(str[l] == '-'){
		if((l-r)%2==0){
			return str[r]-'0';
		}else{
			int a = str[r]-'0';
			if(a == 0) return 2;
			else if(a == 2) return 0;
			else return 1;
		}
	}
	for (i = l+1; i < r; i++)
	{
		if((str[i] == '+' || str[i] == '*') && count == 0) break;
		if(str[i] == '(') count++;
		if(str[i] == ')') count--;
	}
	former = calc_form(l+1, i-1);
	latter = calc_form(i+1, r-1);
	if(str[i] == '*'){
		if(former == 2 && latter == 2) return 2;
		if(former == 0 || latter == 0) return 0;
		else return 1;
	}else if(str[i] == '+'){
		if(former == 2 || latter == 2) return 2;
		if(former == 0 && latter == 0) return 0;
		else return 1;
	}
}

int main(){
	while(1){
		cin >> form;
		if(form[0] == '.') break;
		strcpy(str, form);
		int ans = 0;
		for (int p = 0; p <= 2; p++)
		{
			for (int q = 0; q <= 2; q++)
			{
				for (int r = 0; r <= 2 ; r++)
				{
					for (int i = 0; i < strlen(str); i++)
					{
						if(str[i] == 'P') str[i] = p+'0';
						if(str[i] == 'Q') str[i] = q+'0';
						if(str[i] == 'R') str[i] = r+'0';
					}
					if(calc_form(0, strlen(str)-1) == 2) ans++;
					strcpy(str, form);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:54:17: error: 'strcpy' was not declared in this scope
   54 |                 strcpy(str, form);
      |                 ^~~~~~
a.cc:6:1: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <cmath>
  +++ |+#include <cstring>
    6 | 
a.cc:62:61: error: 'strlen' was not declared in this scope
   62 |                                         for (int i = 0; i < strlen(str); i++)
      |                                                             ^~~~~~
a.cc:62:61: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:68:57: error: 'strlen' was not declared in this scope
   68 |                                         if(calc_form(0, strlen(str)-1) == 2) ans++;
      |                                                         ^~~~~~
a.cc:68:57: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: In function 'int calc_form(int, int)':
a.cc:48:1: warning: control reaches end of non-void function [-Wreturn-type]
   48 | }
      | ^
Language: C++

#include <iostream>
#include <string>
using namespace std;

int nottable[3] = { 2,1,0 };
int andtable[3][3] = { {0,0,0},{0,1,1},{0,1,2} };
int ortable[3][3] = { {0,1,2},{1,1,2},{2,2,2} };

char tochar(int num) {
	if (num == 0) {
		return '0';
	}
	else if (num == 1) {
		return '1';
	}
	else {
		return '2';
	}
}

int solve(string::iterator& iter)
{
	int ret;

	if (*iter == '0') {
		ret = 0;
	}
	else if (*iter == '1') {
		ret = 1;
	}
	else if (*iter == '2') {
		ret = 2;
	}
	else if (*iter == '-') {
		iter++;
		return nottable[solve(iter)];
	}
	else if (*iter == '(') {
		iter++;
		ret = solve(iter);
		
		if (*iter == '+') {
			iter++;
			ret = ortable[ret][solve(iter)];
		}
		else if (*iter == '*') {
			iter++;
			ret = andtable[ret][solve(iter)];
		}
	}

	iter++;

	return ret;
}

int main()
{
	while (true) {
		string str;
		cin >> str;

		if (str == ".") {
			break;
		}

		int ans = 0;

		for (int i = 0; i <= 2; i++) {
			for (int j = 0; j <= 2; j++) {
				for (int k = 0; k <= 2; k++) {
					string temp = str;

					for (int l = 0; l < temp.size(); l++) {
						if (temp[l] == 'P') {
							temp[l] = tochar(i);
						}
						else if (temp[l] == 'Q') {
							temp[l] = tochar(j);
						}
						else if (temp[l] == 'R') {
							temp[l] = tochar(k);
						}
					}

					if (solve(temp.begin()) == 2) {
						ans++;
					}
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:86:61: error: cannot bind non-const lvalue reference of type 'std::__cxx11::basic_string<char>::iterator&' to an rvalue of type 'std::__cxx11::basic_string<char>::iterator'
   86 |                                         if (solve(temp.begin()) == 2) {
      |                                                   ~~~~~~~~~~^~
a.cc:21:29: note:   initializing argument 1 of 'int solve(std::__cxx11::basic_string<char>::iterator&)'
   21 | int solve(string::iterator& iter)
      |           ~~~~~~~~~~~~~~~~~~^~~~