蓝桥 算法提高 盾神与条状项链

#include 
#include 
#include 
using namespace std;
int n,m,p,q;
char s[5];
int main()
{
	while (~scanf ("%d%d",&n,&m)) {
		vector v;
		for (int i=0;i

学长版

#include 
using namespace std;
class List{
    struct Node{
        int value;
        Node* next;
        Node(int _v = 0): value(_v){next = NULL;}
    };
    Node* head;
    int Size;
public:
    List(){Size = 0, head = new Node();}
    int size(){return Size;}
    void push_front(int s){
        Node* p = new Node(s);
        p -> next = head -> next;
        head -> next = p;
        Size++;
    }
    void pop(int s){
    	for(Node* p = head; p->next; p = p->next){
    		if(p->next->value == s){
    			p->next = p->next->next;
    			Size--;
    			break;
    		}
    	}
    }
    void add(int P, int Q){
    	for(Node* p = head; p->next; p = p->next){
    		if(p->next->value == P){
    			Size++;
    			Node* k = new Node(Q);
    			k->next = p->next;
    			p->next = k;
    			break;
    		}
    	}
    }
    void print(){
        for(Node *p = head->next; p; p = p->next)
            printf("%d ", p->value);
    }
};
int main(){
    stack s;
    List l;
    int n, m, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        scanf("%d", &m);
        s.push(m);
    }
    while(s.size()) {
        l.push_front(s.top());
        s.pop();
    }
    while(k--){
        int p, q;
        char s[8];
        scanf("%s", s);
        if(s[0] == 'A'){
            scanf("%d%d",&p, &q);
            l.add(p, q);
        }
        else{
            scanf("%d", &p);
            l.pop(p);
        }
    }
    cout << l.size() << endl;
    l.print();
    return 0;
}


你可能感兴趣的:(蓝桥,stl,STL,蓝桥)