The following program is my ACcepted code for NTHU-5710 .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 5710 的AC code!
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 5710 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
點這裡看題目 Click here to see this Problem!
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
This file contains 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
//This program is for NTHU 5710 Stack | |
//題目來源 Problem link: http://140.114.86.38/problem.php?pid=5710 | |
#include<iostream> | |
#include<stdio.h> | |
#include<stack> | |
#include<string.h> | |
using namespace std; | |
stack<int> s; | |
void stackClear() | |
{ | |
while( !s.empty()) | |
s.pop(); | |
} | |
void stackTop() | |
{ | |
if(s.size() == 0) | |
printf("X\n"); | |
else | |
printf("%d\n", s.top()); | |
} | |
void stackPush(int n) | |
{ | |
s.push(n); | |
} | |
void stackPop() | |
{ | |
if( !s.empty()) | |
s.pop(); | |
} | |
void stackAction(char action[]) | |
{ | |
if(strcmp(action, "top") == 0) | |
stackTop(); | |
else if(strcmp(action, "push") == 0) | |
{ | |
int tmp; | |
scanf("%d", &tmp); | |
stackPush(tmp); | |
} | |
else if(strcmp(action, "pop") == 0) | |
stackPop(); | |
} | |
int main() | |
{ | |
char oper[5]; | |
stackClear(); | |
while(scanf("%s", &oper) != EOF) | |
{ | |
stackAction(oper); | |
} | |
return 0; | |
} |
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!