Last active
August 29, 2015 14:23
-
-
Save macrat/40eac924a2edbbcd0227 to your computer and use it in GitHub Desktop.
昨日のICPCの解答。一応リファクタリングしてある。Bのチェック関数が荒っぽすぎて何か嫌だ。
This file contains hidden or 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> | |
| using namespace std; | |
| int main() | |
| { | |
| int num, min, max; | |
| while(true) | |
| { | |
| cin >> num >> min >> max; | |
| if(num == 0 && min == 0 && max == 0) | |
| break; | |
| int old; | |
| cin >> old; | |
| int maxga=0, maxpos=min; | |
| for(int i=1; i<num; i++) | |
| { | |
| int x; | |
| cin >> x; | |
| if(min <= i && i <= max && old - x >= maxga) | |
| { | |
| maxga = old - x; | |
| maxpos = i; | |
| } | |
| old = x; | |
| } | |
| cout << maxpos << endl; | |
| } | |
| } |
This file contains hidden or 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 <vector> | |
| #include <string> | |
| using namespace std; | |
| int check_count_words(vector<string>::iterator itr, vector<string>::iterator end, int expect) | |
| { | |
| int i=0, len=0; | |
| for(; len<expect && itr!=end; itr++, i++) | |
| len += (*itr).length(); | |
| return len==expect ? i : 0; | |
| } | |
| bool check(vector<string> ls, int shift) | |
| { | |
| int result=0, collect[] = {5, 7, 5, 7, 7}; | |
| vector<string>::iterator itr = ls.begin() + shift; | |
| for(int i=0; i<sizeof(collect)/sizeof(int); i++) | |
| { | |
| itr += result; | |
| if((result = check_count_words(itr, ls.end(), collect[i])) == 0) | |
| return false; | |
| } | |
| return true; | |
| } | |
| int main() | |
| { | |
| while(true) | |
| { | |
| int lineNum; | |
| cin >> lineNum; | |
| if(lineNum == 0) | |
| break; | |
| string read; | |
| vector<string> ls; | |
| for(int i=0; i<lineNum; i++) | |
| { | |
| cin >> read; | |
| ls.push_back(read); | |
| } | |
| for(int i=0; i<ls.size(); i++) | |
| { | |
| if(check(ls, i)) | |
| { | |
| cout << i+1 << endl; | |
| break; | |
| } | |
| } | |
| } | |
| return 0; | |
| } |
This file contains hidden or 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 <string> | |
| #include <stdlib.h> | |
| using namespace std; | |
| class BaseStack | |
| { | |
| protected: | |
| int value; | |
| BaseStack* child; | |
| virtual void push(int value){}; | |
| public: | |
| void feed(string line); | |
| BaseStack() | |
| { | |
| this->child = NULL; | |
| } | |
| int close() | |
| { | |
| if(this->child) | |
| { | |
| this->push(this->child->close()); | |
| delete this->child; | |
| this->child = NULL; | |
| } | |
| return this->value; | |
| } | |
| }; | |
| class AddStack : public BaseStack | |
| { | |
| protected: | |
| void push(int value) | |
| { | |
| this->value += value; | |
| } | |
| public: | |
| AddStack() | |
| { | |
| this->value = 0; | |
| } | |
| }; | |
| class MulStack : public BaseStack | |
| { | |
| protected: | |
| void push(int value) | |
| { | |
| this->value *= value; | |
| } | |
| public: | |
| MulStack() | |
| { | |
| this->value = 1; | |
| } | |
| }; | |
| void BaseStack::feed(string line) | |
| { | |
| if(line.at(0) == '.') | |
| { | |
| this->child->feed(line.substr(1)); | |
| }else | |
| { | |
| this->close(); | |
| if(line == "+") | |
| this->child = new AddStack(); | |
| else if(line == "*") | |
| this->child = new MulStack(); | |
| else | |
| this->push(atoi(line.c_str())); | |
| } | |
| } | |
| int main() | |
| { | |
| while(true) | |
| { | |
| int lineNum; | |
| cin >> lineNum; | |
| if(lineNum == 0) | |
| break; | |
| AddStack stack; | |
| for(int i=0; i<lineNum; i++) | |
| { | |
| string line; | |
| cin >> line; | |
| stack.feed(line); | |
| } | |
| cout << stack.close() << endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment