Created
April 10, 2014 16:42
-
-
Save ofan/10400722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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