Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
代码#include <iostream> #include <string> #include <fstream> #include <stack> #include <sstream> using namespace std; #define M 10000 int a[M]; int n; bool judge() { int sum; stack<int> st; int t; for (int i = 0; i < n; i++) { t = a[i]; if (t < 0) { st.push(t); } else { sum = 0; while (!st.empty() && st.top() != -t) { if(st.top()<0){ return false; } sum += st.top(); st.pop(); } if (st.empty()) { return false; } if(sum>=t){ return false; } st.pop(); st.push(t); } } if(st.size()!=1) return false; if(st.top()<0) return false; return true; } int main() { //cout << "Hello World!!!" << endl; // prints Hello World!!! //ifstream cin("a"); int t; string s; int i; while(getline(cin,s)){ stringstream is(s); i=0; while(is>>t){ a[i++]=t; } n=i; if(judge()){ cout<<":-) Matrioshka!"<<endl; } else{ cout<<":-( Try again."<<endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator