[1159] Luo Gu rankings

 

Title Description

Little Michael lives in a small town, he likes to watch the afternoon release of weekly television music competitions. It introduced the same songs every week based on the votes that lists these songs pop charts.

One Sunday Michael and his friends play too long that they fail to see the new pop charts. He was very disappointed, but he soon found out the next week may partly build Billboard least. In addition to the position of each song, ranking also ranked according to these songs last week's ranking lists information about their movements, more precisely, from this week onwards, regardless of the song is to continue to row in situ, or moved up or lower rankings, will give a little explanation.

Programming, according to Billboard given last week to help Michael infer possible rankings.

Input Format

The first row is an integer N (1≤N≤100) N ( . 1 N . 1 0 0 ), the total number of songs on the list is represented.

The next N N block list ranking information. Each block has two rows, the first row is the i-th block of the i name i song, song comprising no more than 100 . 1 0 0 capital letters, comprising a second row of the following three words: the UP the U- P (song rising position in the charts), DOWN D O W is N (song position on the charts decline) or sAME S a M E (ranking constant), compared with last week charts showing, ranking changes that occur list.

Output Format

N N last rows may output a chart.

Each line contains the name of a song, that is the i-th row contains the first ranking i song i song.

Note: the solution need not be unique, but for each test data is at least one solution.

Sample input and output

Input # 1
5
HIGHHOPES
UP
LOWFEELINGS
UP
UPANDDOWN
DOWN
IAMSTILLSTANDING
DOWN
FOOLINGAROUND
DOWN
Output # 1
UPANDDOWN
IAMSTILLSTANDING
FOOLINGAROUND
HIGHHOPES
LOWFEELINGS

 Solution: simple application queue grace. Green title

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
using namespace std;
string d1[111],d2[111],f[111];
int up,down,now1,now2;
int n;
string s1,s2;
int main(){
    freopen("1159.in","r",stdin);
    freopen("1159.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        cin>>s1>>s2;
        if(s2=="UP")   { up++; d1[up]=s1; }
        if(s2=="DOWN") { down++; d2[down]=s1; }
        if(s2=="SAME")  f[i]=s1;
    }
    for(int i=1;i<=n; i++) {
        if(f[i]!="")continue;
        else{
            if(now1<down) { now1++; f[i]=d2[now1]; } 
            else { now2++; f[i]=d1[now2]; }
        }
    }
    for(int i=1;i<=n;i++)
        cout<<f[i]<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11734794.html