您的位置:首页 > 其它

HDU 5071 Chat

2015-12-31 21:50 555 查看
题意:

CLJ找了很多妹子… (题目好没节操…) 对于CLJ和妹子的聊天对话框 有一下几种操作:

add 加一个妹子在聊天窗队列末尾 假设这个妹子已经在队列中则add失败

close 关掉某个妹子的聊天窗体 假设没有这个妹子的对话框则close失败 假设成功要输出和这个妹子说过几个词

chat 和最前面妹子说一些话 假设没有窗体打开则chat失败

rotate 将某个妹子移到最前面 假设寻找妹子时发现超出队列范围则rotate失败

prior 将优先级最高妹子移到最前面 假设没有对话框则prior失败

choose 选择某个妹子移到最前面 假设该妹子不在队列则choose失败

top 选择某个妹子将她的状态变为总在最前 假设妹子不在队列则top失败 假设以前有总在最前的妹子 则代替之

untop 撤销总在最前状态 假设没人总在最前则untop失败

最后依照队列顺序 与每个以前说过话的妹子道别

思路:

模拟题… 写写写…

总在最前是一种状态 要理解 它并不直接改变队伍形状

即 第三个妹子被top 再被untop 这时这个妹子依旧站在第三个位置上

注意几个坑点:

close时候可能关掉的是总在最前的妹子的对话框 这时总在最前也同一时候消失

chat要用__int64存储每一个妹子对话过几个词

最后道别时候应该先于总在最前的妹子道别

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<bitset>
using namespace std;
typedef __int64 LL;
#define M 5010

struct girl {
int prior;
LL word;
} g[M];
int T, n, tot, alwaysontop;

int main() {
int i, u, j, success, w, x;
char op[30];
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
tot = 0;
alwaysontop = -1;
for (i = 1; i <= n; i++) {
printf("Operation #%d: ", i);
scanf("%s", op);
if (strcmp(op, "Add") == 0) {
scanf("%d", &u);
success = 1;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 0;
break;
}
}
if (success) {
printf("success.\n");
g[tot].prior = u;
g[tot].word = 0;
tot++;
} else
printf("same priority.\n");
} else if (strcmp(op, "Close") == 0) {
scanf("%d", &u);
success = 0;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 1;
u = j;
break;
}
}
if (success) {
if (g[u].prior == alwaysontop)
alwaysontop = -1;
printf("close %d with %I64d.\n", g[u].prior, g[u].word);
for (j = u; j < tot; j++)
g[j] = g[j + 1];
tot--;
} else
printf("invalid priority.\n");
} else if (strcmp(op, "Chat") == 0) {
scanf("%d", &w);
if (alwaysontop != -1) {
for (u = 0; u < tot; u++) {
if (g[u].prior == alwaysontop) {
g[u].word += w;
break;
}
}
printf("success.\n");
} else if (tot > 0) {
g[0].word += w;
printf("success.\n");
} else
printf("empty.\n");
} else if (strcmp(op, "Rotate") == 0) {
scanf("%d", &x);
if (x >= 1 && x <= tot) {
x--;
while (x) {
swap(g[x], g[x - 1]);
x--;
}
printf("success.\n");
} else
printf("out of range.\n");
} else if (strcmp(op, "Prior") == 0) {
if (tot) {
u = 0;
for (j = 1; j < tot; j++) {
if (g[j].prior > g[u].prior)
u = j;
}
while (u) {
swap(g[u], g[u - 1]);
u--;
}
printf("success.\n");
} else
printf("empty.\n");
} else if (strcmp(op, "Choose") == 0) {
scanf("%d", &u);
success = 0;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 1;
u = j;
break;
}
}
if (success) {
while (u) {
swap(g[u], g[u - 1]);
u--;
}
printf("success.\n");
} else
printf("invalid priority.\n");
} else if (strcmp(op, "Top") == 0) {
scanf("%d", &u);
success = 0;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 1;
break;
}
}
if (success) {
alwaysontop = u;
printf("success.\n");
} else
printf("invalid priority.\n");
} else if (strcmp(op, "Untop") == 0) {
if (alwaysontop != -1) {
alwaysontop = -1;
printf("success.\n");
} else
printf("no such person.\n");
}
}
if (alwaysontop != -1) {
for (j = 0; j < tot; j++) {
if (g[j].prior == alwaysontop) {
u = j;
break;
}
}
if (g[u].word)
printf("Bye %d: %I64d\n", g[u].prior, g[u].word);
}
for (j = 0; j < tot; j++) {
if (g[j].word && g[j].prior != alwaysontop) {
printf("Bye %d: %I64d\n", g[j].prior, g[j].word);
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: