Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题

Posted by KatrineYang at 2016-07-14 21:41:07 on Problem 3750
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator