代码来找茬!
最近太无聊了,带大家玩个小游戏,比对上下两个代码,找到三处不同处,最先找到者获10专家分,总共30分,大家加油!代码1:
程序代码:
#include<iostream> #include<stack> using namespace std; stack<int>card; bool flags[10010] = {false}; void get(int n){ if (flags[n] == false) { card.push(n); flags[n] = true; } else return; } int main() { int n, t; cin >> n; for (int i = 0; i < n; i++) { cin >> t; get(t); } for (int i = 0; i < card.size(); i++) { cout << card.top() << " "; card.pop(); } return 0; }
代码2:
程序代码:
#include<istream> #include<stack> using namespace std; stack<int>cards; bool flags[10010] = {false}; void get(int n){ if (flags[n] == false) { card.push(n); flags[n] = true; } else return; } int main() { int n, t; cin >> n; for (int i = 0; i < n; i++) { cin >> t; get(i); } for (int i = 0; i < card.size(); i++) { cout << card.top() << " "; card.pop(); } return 0; }