output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#de... | ### Prompt
Develop a solution in cpp to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <cctype>
#include <cassert>
#include <iostream>
using namespace std;
string S;
size_t cur; //?§£???????§???????
int digit() {
assert(isdigit(S[cur])); //S[cur]?????°?????§???????????¨????¢????
int n = S[cur] - '0'; // '0'???0?????????
cur = cur + 1; //??????????????????
return n;
}
int number() {
int... | ### Prompt
Construct a CPP code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int i;
string str;
int Expression();
int Term();
int Factor();
int No(int);
int main(){
int n;
cin >> n;
while(n--){
cin >> str;
i = 0;
cout << Expression() << endl;
}
}
int Expression(){
int res = Term();
while(1){
s... | ### Prompt
Please provide a CPP coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
//18
#include<iostream>
#include<cctype>
using namespace std;
char s[101];
char *p;
int pp();
int pm();
int pb();
int pp(){
int a=pm();
while(*p=='+'||*p=='-'){
char o=*p++;
int b=pm();
if(o=='+'){
a+=b;
}else{
a-=b;
}
}
return a;
}
int pm(){
int a=pb();
while(*p=='*'||*... | ### Prompt
Create a solution in Cpp for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdlib>
using namespace std;
string query;
const char *p;
int exprs();
int factor() {
char *e;
int ret;
if(*p == '(') {
p ++;
ret = exprs();
p ++;
return ret;
}
ret = strtol(p, &e, 10);
// cout << ... | ### Prompt
Construct a CPP code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include<iostream>
#include<cstdlib>
using namespace std;
typedef pair<int,const char*>parsed;
parsed expr(const char *p);
parsed term(const char *p);
parsed fact(const char *p);
parsed expr(const char *p){
parsed r=term(p);
while(*r.second=='+'||*r.second=='-'){
char op =*r.second;
int tmp=r.first;
r=te... | ### Prompt
Please formulate a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<cstdio>
#include<string>
#include<cctype>
#include<iostream>
#include<algorithm>
using namespace std;
typedef string::const_iterator State;
int expr(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);
int number(State &begin){
int ret=0;
while(isdigit(*begin)){
re... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 100
using namespace std;
int ans;
int n,pointer;
char input[MAX];
int evalE();
int evalT();
int evalF();
int main(){
cin >> n;
rep(i,n){
pointer = 0;
cin >> input;
ans = evalE();
co... | ### Prompt
Please create a solution in CPP to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int number(const string &s, int &k);
int fact(const string &s, int &k);
int term(const string &s, int &k);
int expr(const string &s, int &k){
int result = term(s,k);
while(true){
if(s[k]=='+')result += term(s,++k);
else if(s[k]=='-... | ### Prompt
Please provide a CPP coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cctype>
using namespace std;
string s;
typedef string::const_iterator State;
int expression(State&);
int term(State&);
int number(State&);
int factor(State&);
int expression(State &begin){
int ret = term(be... | ### Prompt
Develop a solution in CPP to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <bits/stdc++.h>
using namespace std;
string s;
int p,n;
int bnf1();
int g_A(){
int r=0;
if(s[p]=='(')p++,r=bnf1(),p++;
else
while(isdigit(s[p])) r=r*10+(s[p++]-'0');
return r;
}
int bnf2(){
int res=g_A();
while(s[p]=='*'||s[p]=='/'){
int t=p++;
if(s[t]=='*')res*=g_A();
if(s[t]=='/')... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cassert>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define fr(i,c) for(_... | ### Prompt
Please create a solution in Cpp to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <complex>
#include <cctype>
#include <cassert>
using namespace std;
int n;
string S;
int cur;
int digit(){
a... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator Iter;
int expr(Iter &p);
int term(Iter &p);
int factor(Iter &p);
int number(Iter &p);
int expr(Iter &p) {
int r = term(p);
for(;;) {
if(*p == '+') {
p++;
int rs = term(p);
r += rs;
}
else if(... | ### Prompt
In cpp, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include <bits/stdc++.h>
using namespace std;
string::const_iterator it;
int number();
int factor();
int term();
int expression();
int number()
{
int ret = 0;
while(isdigit(*it)) {
ret *= 10;
ret += *it - '0';
it++;
}
return ret;
}
int factor()
{
int ret;
... | ### Prompt
Generate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include <iostream>
#include <string>
using namespace std;
string s;
int single(int& pos);
int figure(int& pos);
int solve(int& pos);
int main(){
int T;
cin>>T;
for(int i = 0; i < T; i++){
cin>>s;
int pos = 0;
cout<<solve(pos)<<endl;
}
return 0;
}
int single(int& pos){//??°??????????????????????????¢... | ### Prompt
Your task is to create a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, a... |
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<string>
using namespace std;
class Parsing{
private:
string parse;
int pos;
public:
Parsing(string s){
parse = s;
pos = 0;
}
int fact(){
if(parse[pos] == '('){
pos++;
int p = expression();
pos++;
... | ### Prompt
Please provide a CPP coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <string>
using namespace std;
string S;
int expr(int& p);
int term(int& p);
int factor(int& p);
int number(int& p);
int expr(int& p) {
int v1 = term(p);
while(S[p] == '+' || S[p] == '-') {
char op = S[p];
p++;
int v2 = term(p);
if(op == '+') {
... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include <iostream>
#include <string>
using namespace std;
class calc{
string s;
string::iterator it;
public:
calc(const string&str){
s = str;
it = s.begin();
}
int fact(){
if(*it == '('){
++it;
int ret = exp();
++it;
return ret;
}
else{
int ret = 0;
... | ### Prompt
Construct a CPP code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include<iostream>
using namespace std;
string str;
int p;
int exp();
int term();
int factor();
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
p=0;
cin>>str;
cout<<exp()<<endl;
}
return 0;
}
int exp(){
int val=term();
while(str[p]=='+'||str[p]=='-'){
if(str[p]=='+'){
p++;
... | ### Prompt
Develop a solution in cpp to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
string s;
int id;
int exp();
int term();
int fact();
int exp()
{
int r = term();
while(true)
{
char c = s[id++];
if(c == '+')r += term();
else if(c == '-')r -= term();
else break;
}
return r;
}
int term()
{
int r = fact();
... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <string>
#include <cctype>
#include <cassert>
using namespace std;
string S;
size_t cur = 0;
int digit() {
assert(isdigit(S[cur]));
int n = S[cur++] - '0';
return n;
}
int number() {
int n = digit();
while(cur < S.size() && isdigit(S[cur])) {
n = n*10 + digit()... | ### Prompt
Your task is to create a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, a... |
#include<iostream>
#include <string>
using namespace std;
int weak(string& s, int& i);
int strong(string& s, int& i);
int fc(string& s, int& i);
int inte(string& s, int& i);
int weak(string& s, int& i) {
int buf = strong(s, i);
while (s[i] == '+' || s[i] == '-') {
if (s[i] == '+') {
i++;
buf += strong(s, i)... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <string>
using namespace std;
int expression();
int term();
int factor();
int number();
int now;
string s;
int expression(){
int res=term();
while(true){
if(s[now]=='+'){
now++;
res+=term();
}else if(s[now]=='-'){
now++;
res-=term();
}else
b... | ### Prompt
Construct a cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0109&lang=jp
// Appendix??????????????????
#include <bits/stdc++.h>
using namespace std;
int n, cur;
string str;
int expression();
int factor();
int digit() {
assert(isdigit(str[cur]));
int n = str[cur] - '0';
cur++;
return n;
}
int number() {
... | ### Prompt
Please formulate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <string>
using namespace std;
int hyoka(string);
int isNum(int);
int main(){
int n,i;
string s;
cin>>n;
for(i=0;i<n;i++){
cin>>s;
cout<<hyoka(s)<<endl;
}
return 0;
}
int hyoka(string s){
long int total=0,work=0;
long int tmp1,tmp2;
int oi=0;
char oc;
int n;
string ... | ### Prompt
In Cpp, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
using State = string::const_iterator;
int expression(State& begin);
int term(State& begin);
int factor(State& begin);
int number(State& begin);
int expression(State& begin){
int ret = term(begin);
while (true){
if (*begin == '+'){
... | ### Prompt
In cpp, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>
int parse_int(std::string const& s, size_t& i) {
int res = s[i]-'0';
while (isdigit(s[++i]))
res = res*10 + s[i]-'0';
return res;
}
int apply(int lhs, char op, int rhs) {
if (... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#if 0
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
string S;
size_t cur;
char readchar() {
assert(cur < S.size());
return S[cur++];
}
char peek() {
assert(cur < S.size());
return S[cur];
}
int digit() {
assert(isdigit(peek()));
int n = readchar() - '0';
return n;
}
in... | ### Prompt
Please formulate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<iostream>
#include<string>
using namespace std;
int p;
string exp;
int term();
int expression();
int factor();
int expression(){
int value;
value=term();
while(exp[p]=='+' || exp[p]=='-'){
if(exp[p]=='+'){
p++;
value+=term();
}
else{
p++;
value-=term();
}
}
return v... | ### Prompt
Generate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
/*
Expr = Term { (+|-) Term}
Term = Fact { (*|/) Fact}
Fact = (Expr) | number
*/
#include<iostream>
#include<cstdlib>
using namespace std;
typedef pair<int,const char*>parsed;
parsed expr(const char *p);
parsed term(const char *p);
parsed fact(const char *p);
parsed expr(const char *p)
{
parsed r=term(p... | ### Prompt
Generate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include <iostream>
#include <string>
using namespace std;
string input;
int pos;
int fact();
int term();
int expr();
int fact() {
int result = 0;
if (input[pos] == '(') {
pos++;
result = expr();
pos++;
} else {
while (isdigit(input[pos])) {
result = result * 10 + input[pos] - '0';
pos++;
}
}
//... | ### Prompt
Generate a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
using namespace std;
int exp(string &s, int &i);
int term(string &s, int &i);
int factor(string &s, int &i);
int number(string &s, int &i);
int exp(string &s, int &i)
{
int val = term(s, i);
while(s[i] == '+' || s[i] == '-'){
char op = ... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include<iostream>
#include<string>
#include<cassert>
#include<cctype>
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
using namespace std;
string S;
size_t cur = 0;
int term();
int factor();
int expression();
int digit(){
assert(isdigit(S[cur]));
int n = S[cur] - '0';
cur = cur + 1;
return n;
}
int nu... | ### Prompt
Please create a solution in CPP to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
string s;
int conv_stoi(string str){
stringstream ss(str);
int n;
ss >> n;
return n;
}
int parse(int l, int r){
int n = 0;
for(int i=r-1;i>=l;i--){
if(s[i] == ')') n++;
if(s[i] == '(') n--;
if(!n){
if(s[i] == '+'... | ### Prompt
Your task is to create a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, a... |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
int factor(State &begin);
int number(State &begin)
{
int ret = 0;
while(isdigit(*begin))
{
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
int term(State &begin)
{
int ret = fact... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include<iostream>
#include<string>
#include<vector>
using namespace std;
string S;
char U[11]="0123456789";
int junjo[4]={0,0,1,1};
long long STOI(string V){
int LEN=V.size();
if(LEN==0){return 0;}
return (V[LEN - 1] - '0') + 10 * ( STOI(V.substr(0, LEN - 1)) );
}
long long calc(int L,int R){
int K=0;
vector<in... | ### Prompt
Generate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include <iostream>
#include <string>
using namespace std;
class calc{
string s;
string::iterator it;
public:
calc(string str){
s = str;
it = str.begin();
}
int fact(){
if(*it == '('){
*it++;
int ret = exp();
*it++;
return ret;
} else {
int ret = 0;
while(... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string str;
int cur = 0;
int expression();
int term();
int factor();
int expression();
int digit() {
int a = str[cur] - '0';
cur++;
return a;
}
int number() {
int a = digit();
while (cur < str.size() && isdigit(str[cu... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <cassert>
#include <cctype>
using namespace std;
string S;
size_t cur;
int digit() {
assert(isdigit(S[cur]));
int n = S[cur] - '0'; // ASCII code -> digit
cur = cur+1;
return n;
}
int number() {
int n = digit();
while (cur<S.size() && isdigit(S[cur])) {
n = n*10 + digit()... | ### Prompt
In cpp, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int N;
int c;
int expr();
int term();
int factor();
int num();
void debug(string text){
return;
cout << text + " ";
for(int i = 0; i < N; i++){
if(i == c) cout << '[' << s[i] << ']';
else cout << s[i];
}
cout << endl;
}
int expr(... | ### Prompt
Develop a solution in CPP to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int solve(st... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
struct Parsing {
int expression(State& it) {
int res = term(it);
while (true) {
if (*it == '+') res += term(++it);
else if (*it == '-') res -= term(++it);
else break;
}
return res;
}
... | ### Prompt
Develop a solution in CPP to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
string S;
size_t cur = 0;
int digit(){
assert(isdigit(S[cur]));
int n = S[cur] - '0';
cur += 1;
return n;
}
int number(){
int n = digit();
while(cur<S.size()&&isdigit(S[cur])){
n = n*10 + digit();
}
return n;
}
int fa... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <cctype>
#include <string>
#include <cassert>
using namespace std;
string S;
size_t cur;
int x;
char readchar(){
assert(cur < S.size());
return S[cur++];
}
char peek(){
assert(cur < S.size());
return S[cur];
}
int digit(){
assert(isdigit(peek()));
int n = readchar() - '0';
retur... | ### Prompt
Create a solution in Cpp for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <cstdio>
#include <cctype>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
int apply(int lhs, char op, int rhs) {
switch (op) {
case '+': return lhs+rhs;
case '-': return lhs-rhs;
case '*': return lhs*rhs;
case '/': return lhs/rhs;
}
assert(false);
}
int parse(const ... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
using namespace std;
string S;
size_t cur = 0;
int expression();
int digit();
int number();
int parse();
int term();
int factor();
int main(){
int n;
cin >> n;
for (int i=0; i<n; i++){
cin >> S;
int a = parse();
// assert (a... | ### Prompt
In CPP, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
int culc1();
int culc2();
int culc3();
int culc4();
int n;
string str;
int cur;
int main() {
cin >> n;
while (n--) {
cin >> str;
cur = 0;
cout << culc1() << endl;
}
return 0;
}
int culc... | ### Prompt
Develop a solution in cpp to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <cassert>
#include <cctype>
using namespace std;
string S;
size_t cur;
int digit() {
assert(isdigit(S[cur])); // S[cur]が数字でなければストップ。正しく動作すれば実行されない。
int n = S[cur] - '0';
cur++;
return n;
}
int number() {
int n = digit();
while (cur < S.size() && isdigit(S[cur])) {
n = n ... | ### Prompt
Please formulate a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int expression();
int term();
int factor();
int number();
int now;
string s;
int expression(){
int res=term();
while(true){
if(s[now]=='+')now++,res+=term();
else if(s[now]=='-')now++,res-=term();
else break;
}
return res;
}
in... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
string S;
size_t cur;
int parse();
int digit(){
assert(isdigit(S[cur]));
int n=S[cur]-'0';
cur++;
... | ### Prompt
In cpp, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.b... | ### Prompt
Construct a cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
string st;
int a;
int plmi();
int num() {
int n = 0;
while (1) {
if (isdigit(st[a])) {
n *= 10;
n += st[a] - '0';
a++;
}
else {
return n;
}
}
}
int siki() {
int n;
if (st[a] == '(') {
a++;... | ### Prompt
Construct a CPP code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include <cctype>
#include <string>
#include <iostream>
using namespace std;
typedef string::const_iterator State;
int number(State& it) {
int result = 0;
while (isdigit(*it)) {
result *= 10;
result += (*it) - '0';
++it;
}
return result;
}
int expression(State&);
int factor(State& it) {
if (*it == '(') {
... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <string>
#include <cctype>
#include <iostream>
typedef std::string::iterator State;
using namespace std;
int number(State &begin);
int factor(State &begin);
int expression(State &begin);
int main(void){
int N;
std::cin >> N;
while(N--){
std::string s;
std::cin>>s;
State begin = s.begin()... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <cctype>
/** memo
* expr ::= term { ( '+' | '-' ) term }
* term ::= fact { ( '*' | '/' ) fact }
* fact ::= '(' expr ')' | digit
**/
using namespace std;
int expr();
int term();
int fact();
char buf[101];
int p;
int expr() {
int v = term();
while(buf[p] == '+' || buf[p] == '-') {
... | ### Prompt
Please formulate a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <bits/stdc++.h>
using namespace std;
class Calc{
private:
int idx;
string s;
public:
Calc(string s) : s(s) {
idx = 0;
}
int fact(){
int res = 0;
if(s[idx] == '('){
idx++;
res = exp();
idx++;
}else{
while(isdigit(s[idx])){
res *= 10;
res += s[i... | ### Prompt
Generate a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include <bits/stdc++.h>
#define int long long
using namespace std;
// exp1 = exp2 [ ('+'|'-') exp2 ]*
// exp2 = exp3 [ ('*'|'/') exp3 ]*
// exp3 = '(' exp1 ')' | number
int exp1(const string& s, int& i);
int exp2(const string& s, int& i);
int exp3(const string& s, int& i);
int number(const string& s, int& i);
int exp... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int number(string::const_iterator &c){//number
int ret = 0;
while(isdigit(*c)){
ret*=10;
ret+=*c-'0';
c++;
}
return ret;
}
int expression(string::const_iterator&);
int factor(string::const_iterator &c) {
int ret;
if (*c=='(') {
... | ### Prompt
Please create a solution in cpp to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <bits/stdc++.h>
using namespace std;
int Num();
int Fact();
int Term();
int Exp();
int ite;
string s;
int Num() {
int res = 0;
while (isdigit(s[ite])) {
res = res * 10 + s[ite] - '0';
ite++;
}
return res;
}
int Fact() {
if (s[ite] == '(') {
ite++;
int res = Exp();
ite++;
return res;
}
el... | ### Prompt
Please create a solution in CPP to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <bits/stdc++.h>
#define P int
using namespace std;
string s;
int p;
P bns1();
P g_A(){
P r=0;
if(s[p]=='('){
p++;
r=bns1();
p++;
}
else{
while(isdigit(s[p])){
r=r*10+(s[p]-'0');
p++;
}
}
return r;
}
P bns2(){
P res=g_A();
while(s[p]=='*'||s[p]=='/'){
int t=p+... | ### Prompt
Construct a cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include<iostream>
#include<cassert>
#include<string>
#include<cctype>
using namespace std;
string S;
size_t cur = 0;
int parse();
int digit();
int number();
int expression();
int term();
int factor();
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> S;
cur = 0;
S.resize(S.size() - 1);
co... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
string s;
int p;
int expr();
int num() {
int res = 0;
while (p < s.size() && '0' <= s[p] && s[p] <= '9') {
res *= 10;
res += s[p] - '0';
p++;
}
return res;
}
int factor() {
int res = 0;
if (s[p... | ### Prompt
Please create a solution in Cpp to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
char s[125];
int it;
int dfs(){
int ret = 0;
int tail = 0;
int sign = 1;
// first operand
int a = 0;
if(s[it]=='('){
it++;
a = dfs();
assert(s[it]==')');
it++;
}else{
whil... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
int expression(State &begin);
int number(State &begin)
{
int ret = 0;
for(; isdigit(*begin); begin++) {
ret = ret * 10 + *begin - '0';
}
return ret;
}
int factor(State &begin)
{
if(*begin ... | ### Prompt
Construct a cpp code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int N;
int c;
int expr();
int term();
int factor();
int num();
void debug(string text){
return;
cout << text + " ";
for(int i = 0; i < N; i++){
if(i == c) cout << '[' << s[i] << ']';
else cout << s[i];
}
cout << endl;
}
int expr(... | ### Prompt
Develop a solution in cpp to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int expression();
int term();
int factor();
int number();
int now;
string s;
int expression(){
int res=term();
while(true){
if(s[now]=='+')now++,res+=term();
else if(s[now]=='-')now++,res-=term();
else break;
}
... | ### Prompt
Please formulate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<string>
#include<cstdlib>
#include<iostream>
using namespace std;
int prior[128];
long long parse(string s)
{
if(s[0]=='(' && s[s.length()-1]==')'){
bool f=true;
for(int i=1,d=1;i<s.length()-1;i++){
if (s[i]=='(') d++;
else if(s[i]==')') d--;
if(d==0){ f=false; break; }
}
if(f) return ... | ### Prompt
Please create a solution in CPP to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
bool match(char c, string s)
{
rep(i, 0, s.length()) if (s[i] == c) return true;
return false;
}
string op[2] = { "+-", "*/" };
int parse(string s, int &i, int x)
{
if (x == 2)
{
if (s[i] == '(')
{
i++;
int ans = pars... | ### Prompt
Create a solution in cpp for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <string>
using namespace std;
int exp();
int term();
int factor();
int number();
int digit();
string str;
int p,len,val;
int exp(){
int val = term();
while( str[p] == '+' || str[p] == '-' ){
if( str[p] == '+' ){
p++;
val += term();
}else if( str[p] == '-' ){
... | ### Prompt
Create a solution in cpp for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include<bits/stdc++.h>
using namespace std;
int p=0;
int formula(string& s);
int num(string& s){
int res=0;
int op=1;
if(s[p]=='-'){
op=-1;
p++;
}
else if(s[p]=='+'){
op=1;
p++;
}
while(isdigit(s[p])){
res*=10;
res+=s[p]-'0';
p++;
... | ### Prompt
Generate a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include<iostream>
#include<stack>
#include<string>
#include <sstream>
using namespace std;
string s;
int idx;
int term();
int expr();
int fact();
int number();
// <term> = <fact> { (‘*’|‘/’) <fact> }
int term(){
int res = fact();
while(s[idx] == '*' || s[idx] == '/'){
char op = s[idx++];
int tmp = fact(... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include<bits/stdc++.h>
using namespace std;
char* p;
int number();
int term();
int expression();
int program();
int main(){
int n; cin>>n;
char x[100];
for(int i=0;i<n;i++){
scanf("%s",x);
p=x;
cout<<expression()<<endl;
}
return 0;
}
int program(){
int num;
if(*p=='('){
p++;
num=expression();
p... | ### Prompt
Please formulate a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <string>
#include <cctype>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
string src;
int pos;
bool end() { return pos >= src.length(); }
char peek() { return src[pos]; }
void succ() { if (!end()) ++pos; }
int parse_expr();
int lex_number()
{
int val = 0;
char c = peek(... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include<iostream>
#include<string>
#include<cstddef>
#include <cassert>
#include<cctype>
using namespace std;
string S;
size_t cur=0;
int n;
void init_S(){
cur=0;
}
char readchar(){
assert(cur<S.size());
char ret=S[cur];
cur+=1;
return ret;
}
char peek(){
return S[cur];
}
int digit(){
... | ### Prompt
Generate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
string in;
int calc(int l,int r)
{
int pa=0;
for(int i = r; i >= l; --i)
{
if(in[i]==')') pa++;
else if(in[i]=='(') pa--;
else if(!pa)
{
if(in[i]=='+') return calc(l,i-1)+calc(i+1,r);
if(in[i]=='-') return calc(l,i-1)-calc(i+1,... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int pos;
string str;
int exp();
int factor() {
if(str[pos] >= '0' && str[pos] <= '9') {
string tmp = "";
while(str[pos] >= '0' && str[pos] <= '9') {
tmp += str[pos++];
}
return atoi(tmp.c_str());
}
if(str[pos] ... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include<iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
class ParseError {};
int expression(State& base);
int number(State& base){
int ret=0;
while(isdigit(*base)){
ret=ret*10+(*base-'0');
base++;
}
return ret;
}
int factor(Sta... | ### Prompt
Please create a solution in cpp to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int expression(string,int&);
int term(string,int&);
int factor(string,int&);
int number(string,int&);
bool f;
int expression(string s,int& p){
int res=term(s,p);
while(p<(int)s.size()){
if(s[p]=='+'){
p++;
res+=term(s,p);
con... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <cassert>
#include <string>
using namespace std;
string S;
size_t cur=0;
int term();
int expression();
int digit(){
assert(isdigit(S[cur]));
int n = S[cur] - '0';
cur++;
return n;
}
int number(){
int n=digit();
while(cur <S.size() && isdigit(S[cur]))
n=n*10+digit();
return n... | ### Prompt
Construct a CPP code solution to the problem outlined:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, ... |
#include <iostream>
#include <string>
using namespace std;
string str;
int p;
int exp();
int factor();
int term();
int factor() {
int num=0;
while('0' <= str[p] && str[p] <= '9') {
num*=10;
num += str[p] - '0';
p++;
}
if (str[p] == '('){
p++;
num = exp();
p++;
}
return num;
}
int... | ### Prompt
Your task is to create a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, a... |
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
char siki[200];
int cur;
int digit(){
int n=siki[cur]-'0';
++cur;
return n;
}
int number(){
int n=digit();
while(cur<strlen(siki) && isdigit(siki[cur]))
n=n*10+digit();
return n;
}
int fac... | ### Prompt
Please formulate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
// 再帰的下向き構文解析
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
int expression(void);
string str;
int pos;
int factor(void){
int num = 0;
if( isdigit( str[pos] ) ){ // '0' <= str[pos] && str[pos] <= '9'
while( isdigit( str[pos] ) ){
num *= 10;
... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <string>
using namespace std;
string s;
int si(int&);
int fi(int&);
int so(int&);
int main(){
int n;
cin >> n;
for (int i = 0; i < n; i++){
cin >> s;
int pos = 0;
cout << so(pos) << endl;
}
return 0;
}
int so(int& pos){
int ans = fi(pos);
while (s[pos] != '=' && s[pos] != '... | ### Prompt
In cpp, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
using namespace std;
#define INF (1<<25)
#define P(a,b) make_pair(a,b)
int id = 0;
string s;
int exp();
int term();
int fact();
int exp(){
int ans = term();
while(true){
... | ### Prompt
Generate a cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtr... |
#include <iostream>
#include <cstring>
#include <cctype>
#include <cassert>
using namespace std;
string S;
size_t cur = 0;
char readchar() {
assert(cur < S.size());
char ret = S[cur];
cur++;
return ret;
}
char peek() {
assert(cur < S.size());
return S[cur];
}
int digit() {
assert(isdigit(peek()));
... | ### Prompt
Develop a solution in Cpp to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <cassert>
#include <string>
#include <cctype>
using namespace std;
int cur = 0;
string S;
int expression();
int term();
int factor();
int main() {
int times;
cin >>times;
for(int i = 0 ; i < times; i++){
cin >> S;
cur = 0;
S.resize(S.size()-1);
cout << express... | ### Prompt
In Cpp, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include<iostream>
#define INF (1<<26)
using namespace std;
int n;
int compute(int a,int b,string str){
int i=a,sum=0,tmp=INF,tmp2=INF,cnt=0;
while(1){ //cout<<a<<' '<<b<<endl;
sum=0;
if(str[i]=='('){
sum=compute(i+1,0,str);
//cout<<sum<<endl;
cnt=0;
for(i=i;i<(int)str.size(... | ### Prompt
Create a solution in Cpp for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <string>
using namespace std;
int k,n,ans;
string s;
int calc1();
int calc2();
int calc3();
int calc1(){
int a;
a=calc2();
while(s[k]=='+' ||s[k]=='-'){
if(s[k]=='+'){
k++;
a+=calc2();
}else if(s[k]=='-'){
k++;
a-=calc2();
}
}
return a;
}
int calc2(){
int a;
a=c... | ### Prompt
Please formulate a Cpp solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
using namespace std;
string S="";
int cur=0;
char readchar()
{
assert(cur<S.size());
return S[cur++];
}
char peek()
{
assert(cur<S.size());
return S[cur];
}
int digit()
{
assert(isdigit(peek()));
int n=readchar()-'0';
return n;
}... | ### Prompt
Develop a solution in Cpp to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <iostream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main() {
char c[100],*st;
int n,f,ca1,ca2,d;
stack<int> as;
stack<char> bs;
cin >> n;
for (n;n>0;n--) {
cin >> c; st=c;
while(true) {
if (st[0]=='=') break;
f=0; d=0;
if (st[0]=='-') ... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <string>
using namespace std;
string str;
int pos;
int exp();
int term();
int factor();
int henkan(string);
int ruijou(int);
int main(){
int n;
cin >> n;
for(int i=0;i<n;i++){
str="";
getchar();
while(1){
char temp;
cin >> temp;
if(temp=='=') break;
... | ### Prompt
In CPP, your task is to solve the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... |
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef pair<int,int> result;
#define value first
#define p second
result equation(const string &s, int p = 0);
result factor(const string &s, int p=0);
result term(const string &s, int p=0);
result equation(const string &s,int p) {
result... | ### Prompt
Please provide a CPP coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <cassert>
#include <string>
#include <cctype>
using namespace std;
string S;
size_t cur=0;
int digit() {
assert(isdigit(S[cur]));
int n = S[cur] - '0';
cur++;
return n;
}
int number() {
int n = digit();
while(cur < S.size() && isdigit(S[cur])) {
n = n*10 + digit();
}
... | ### Prompt
Develop a solution in CPP to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<iostream>
#include<cassert>
#include<cctype>
using namespace std;
string S;
int cur;
int expression();
int digit(){
assert(isdigit(S[cur]));
int n=S[cur]-'0';
cur=cur+1;
return n;
}
int number(){
int n=digit();
while(cur<S.size()&&isdigit(S[cur])){
n=n*10+digit();
}
retu... | ### Prompt
Please formulate a CPP solution to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <cassert>
#include <cctype>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string S = "";
int cur;
int digit(){
assert(isdigit(S[cur]));
int n = S[cur] - '0';
cur = cur+1;
return n;
}
int number(){
int n = digit();
while(cur < S.size() && isdigit(S[cur]... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represent... |
#include <iostream>
#include <string>
using namespace std;
int hyoka(string);
int isNum(int);
int main(){
int n,i;
string s;
cin>>n;
for(i=0;i<n;i++){
cin>>s;
cout<<hyoka(s)<<endl;
}
return 0;
}
int hyoka(string s){
int total=0,work=0;
int tmp1,tmp2;
int oi=0;
char oc;
int n;
string cs;
if(... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
#include <iostream>
#include <string>
#include <cctype>
#include <cassert>
#include <algorithm>
using namespace std;
size_t cur;
string s;
int expression();
int digit(){
assert(cur < s.size());
return s[cur++] - '0';
}
int number(){
int n = 0.0;
assert(cur < s.size());
while(cur < s.size() && isdigit(s[cur]... | ### Prompt
Please create a solution in cpp to the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include <bits/stdc++.h>
using namespace std;
using State = string::const_iterator;
int expression(State& s);
int number(State& s)
{
int res = 0;
while (isdigit(*s)) {
res *= 10;
res += *s - '0';
s++;
}
return res;
}
int factor(State& s)
{
if (*s == '(') {
s++;
int res = expression(s);
... | ### Prompt
Develop a solution in Cpp to the problem described below:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, additio... |
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
typedef string::const_iterator State;
int expression(State &);
int term(State &);
int factor(State &);
int number(State &);
int main(void){
int N;
cin >> N;
cin.ignore();
for(int i=0;i<N;i++){
string s;
getline(cin,s);
S... | ### Prompt
Create a solution in CPP for the following problem:
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, sub... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.