Skip to content

Instantly share code, notes, and snippets.

@ik11235
Created December 17, 2014 08:11
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 ik11235/889db55a1fac43a4918c to your computer and use it in GitHub Desktop.
Save ik11235/889db55a1fac43a4918c to your computer and use it in GitHub Desktop.
inline int toInt(std::string s) {int v; std::istringstream sin(s);sin>>v;return v;}
class ForgetfulAddition {
public:
int minNumber(string expression) {
int ans=9999999;
for(int i=1;i<expression.size();i++)
{
string a=expression.substr(0,i);
string b=expression.substr(i);
// cerr<<a<<"+"<<b<<endl;
ans=min(ans,toInt(a)+toInt(b));
}
return ans;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment