Skip to content

Instantly share code, notes, and snippets.

@ofan
Created April 10, 2014 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ofan/10400722 to your computer and use it in GitHub Desktop.
Save ofan/10400722 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]){
string in(argv[1]);
long res=0;
int pn = 0;
for(auto i=in.begin(); i!=in.end(); ++i){
if(*i == '+') {
res += pn;
}else if(*i == '*'){
res += (*(++i)-'0')*pn;
pn=0;
}else{
pn = *i-'0';
}
}
res+=pn;
cout << "= " << res << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment