題目地址:點擊打開鏈接
C++代碼:
#include#include #include #include #include #include #include #include using namespace std; int main() { int IntMin=numeric_limits ::min(); string s; while(getline(cin,s)) { istringstream input(s); int x; vector vi; while(input>>x) vi.push_back(x); int i,size; i=0; size=vi.size(); vector > vp; vp.push_back(make_pair(vi[0],0)); for(i=1;i =0&&vp[j].first==IntMin) { ans+=fabs((double)vp[j].second); --j; } if(j<0) break; if(vi[i]==-vp[j].first) { if(ans>=fabs((double)vi[i])) break; vp.erase(vp.begin()+j,vp.end()); vp.push_back(make_pair(IntMin,vi[i])); } else vp.push_back(make_pair(vi[i],0)); } if((i>=size)&&(vp.size()==1)&&vp[0].first==IntMin) cout<<":-) Matrioshka!"<