Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
水题#include <iostream> #include <string> using namespace std; class node{ public: string name; node* next; node* prev; node(string n): name(n), next(this), prev(this){} }; int main() { int n; cin >> n; string s; cin >> s; node *head = new node(s); node *tail = head; for(int i = 0; i < n-1; i++){ cin >> s; node *nnode = new node(s); nnode->next = head; nnode->prev = tail; tail->next = nnode; head->prev = nnode; tail = nnode; } int size = n; int qd, step; char fei; cin >> qd >> fei >> step; node *qidian = head; for(int i = 0; i < qd-1; i++){ qidian = qidian->next; } while(size > 0){ int go = (step-1) % size; for(int i = 0; i < go; i++){ qidian = qidian->next; } cout << qidian->name << endl; size--; if(size == 0) break; qidian->next->prev = qidian->prev; qidian->prev->next = qidian->next; qidian = qidian->next; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator