0
点赞
收藏
分享

微信扫一扫

Aizu ALDS1_3_B Queue

以前干嘛去了 2022-02-22 阅读 68
数据结构

Aizu ALDS1_3_B Queue

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
int n,q,ti;
int head,tail;
struct node{
    char s[15];
    int t;
}a[200005],x;
void push(node x){
    a[++tail]=x;
}
void pop(){
    head++;
}
int main()
{
    head=0;tail=-1;ti=0;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>x.s>>x.t;
        push(x);
    }
    while(head<=tail){
        if(a[head].t>q){
            a[head].t=a[head].t-q;
            push(a[head]);ti+=q;
        }else{
            ti+=a[head].t;
            cout<<a[head].s<<' '<<ti<<endl;
        }
        pop();
    }
    return 0;
}

举报

相关推荐

0 条评论