万能栈?
crh380am_0204 · · 算法·理论
力争有趣保证没用。\ 这是一个十分正常的栈。
#include <bits/stdc++.h>
#define int long long
using namespace std;
stack <int> st;
signed main(){
int n;
cin >> n;
for(int i=1;i<;n;i++){
int x;
cin >> x;
st.push(x);
}
return 0;
}
经过一点魔改,我们就能让他变成一个万能栈。
///太懒了只写了输入
#include <bits/stdc++.h>
using namespace std;
struct k {
int i;
long long l;
unsigned long long ull;
char c;
string s;
double d;
float f;
vector <int> vi;
vector <long long> vl;
vector <unsigned long long> vull;
vector <char> vc;
vector <string> vs;
vector <double> vd;
vector <float> vf;
};
stack <k> st;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string ss;
cin >> ss;//输入完之后一定要换行!一定要换行!
k x;
if (ss == "int") {
cin >> x.i;
}
if (ss == "long long") {
cin >> x.l;
}
if (ss == "unsigned long long") {
cin >> x.ull;
}
if (ss == "char") {
cin >> x.c;
}
if (ss == "double") {
cin >> x.d;
}
if (ss == "float") {
cin >> x.f;
}
if (ss == "string") {
cin >> x.s;
}
if (ss == "vectorint") {
int y;
while (cin >> y) {
x.vi.push_back(y);
}
}
if (ss == "vectorlonglong") {
long long y;
while (cin >> y) {
x.vl.push_back(y);
}
}
if (ss == "vectorunsignedlonglong") {
unsigned long long y;
while (cin >> y) {
x.vull.push_back(y);
}
}
if (ss == "vectorchar") {
char y;
while (cin >> y) {
x.vc.push_back(y);
}
}
if (ss == "vectordouble") {
double y;
while (cin >> y) {
x.vd.push_back(y);
}
}
if (ss == "vectorfloat") {
float y;
while (cin >> y) {
x.vf.push_back(y);
}
}
if (ss == "vectorstring") {
string y;
while (cin >> y) {
x.vs.push_back(y);
}
}
st.push(x);
}
return 0;
}
孩子们这并不好笑。