# 14229: 【原4229】Paper Citation

### 题目描述

author: Shuhao Li 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4229

## Sample Input

``````3
query
query
query
finish
``````

## Sample Output

``````2 1
1 2
2 3
``````

## BugenZhao's solution

``````//
// Created by BugenZhao on 2019/4/29.
//

#include <iostream>
#include <string>

using std::ios, std::cin, std::cout, std::endl, std::string;
using ll = long long;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
auto counts = new int[N + 1]{};
int maxPos = 0;
int maxCount = 0;

string cmd;
int a, b;
while (true) {
cin >> cmd;
if (cmd[0] == 'f') break;
else if (cmd[0] == 'a') {
cin >> a >> b;
++counts[b];
if (counts[b] == maxCount) {
maxPos = maxPos < b ? maxPos : b;
} else if (counts[b] == maxCount + 1) {
maxCount += 1;
maxPos = b;
}
} else if (cmd[0] == 'q') {
cout << maxPos << ' ' << maxCount << '\n';
}
}

delete[] counts;
return 0;
}
``````

## ligongzzz's solution

``````#include "iostream"
#include "cstdio"
#include "cstring"
using namespace std;

int val_num[50009] = { 0 };

int main() {
int n;
scanf("%d", &n);

int cur_max = 0, max_n = 0;
while (true) {
char op[10];
scanf("%s", op);
if (strcmp(op, "add") == 0) {
int a, b;
scanf("%d %d", &a, &b);
++val_num[b];
if (val_num[b] == max_n) {
if (b < cur_max) {
cur_max = b;
}
}
if (val_num[b] > max_n) {
cur_max = b;
max_n = val_num[b];
}
}
else if (strcmp(op, "query") == 0) {
printf("%d %d\n", cur_max, max_n);
}
else {
break;
}
}

return 0;
}
``````

## skyzh's solution

``````#include <iostream>
#include <cstdio>

using namespace std;

int ref_cnt[250001] = {0};

inline char get_cmd() {
char ch;
while (ch = getchar()) {
if ('a' <= ch && ch <= 'z') return ch;
}
}

inline int get_int() {
int x = 0;
char ch;
while (ch = getchar()) {
if ('0' <= ch && ch <= '9') break;
}
do {
if ('0' <= ch && ch <= '9') {
x = x * 10 + (ch - '0');
} else break;
} while (ch = getchar());
return x;
}

int main() {
int n;
n = get_int();
char cmd;
int op1, op2;
int cur_max = 0, cur_max_idx = 0;
while (true) {
cmd = get_cmd();
switch (cmd) {
case 'a':
op1 = get_int();
op2 = get_int();
++ref_cnt[op2];
if (ref_cnt[op2] > cur_max || ref_cnt[op2] == cur_max && op2 < cur_max_idx) {
cur_max = ref_cnt[op2];
cur_max_idx = op2;
}
break;
case 'f':
return 0;
case 'q':
printf("%d %d\n", cur_max_idx, cur_max);
break;
}
}
return 0;
}
``````

## yyong119's solution

``````#include <cstdio>
#include <iostream>
#define MAX_N 50010
int n, cur_max_id, x;
int a[MAX_N];
char op;
inline int read() {
char ch = getchar(); int res = 0;
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9')
res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
return res;
}
int main() {
op = getchar();
while (op != 'f') {
if (op == 'q') {
printf("%d %d\n", cur_max_id, a[cur_max_id]);
while (op != '\n') op = getchar();
}
else if (op == 'a') {