HDU2451 Simple Addition Expression

来源:互联网 发布:阿里云登录账号是什么 编辑:程序博客网 时间:2024/05/16 01:41
/*HDU2451思想不是太难,要细心*/#include <iostream>#include <string>#include <cmath>using namespace std;int main(){string s;while(cin>>s){int i, ans = 0,temp;for(i = 0; i < s.length(); i++){//获取第i位上数字的值temp = s[i] - '0';//如果是最后一位,可选择0、1、2if( i == s.length() - 1){if(temp < 3)ans = ans + temp ;else ans = ans + 3;continue;}//如果是最后一位,可选择0、1、2、3if(temp < 4)ans = ans + temp * pow(4.0, (s.length()-2-i)*1.0) * 3;else{ans = ans + pow(4.0, (s.length()-i-1)*1.0) * 3;break;}}cout<<ans<<endl;}return 0;}