| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
POJ数据是不是有问题呀?!我UVA过了但是POJ没有过我在洛谷上面远程提交到UVA的数据通过了,但是在POJ莫名不知道为什么没有通过,请大佬帮忙看看哪里写错了呀555
代码:
#include <iostream>
#include <cstring>
#include <string>
#include <stack>
#include <cstdio>
using namespace std;
stack<string> stk;
string s;
int lson[26], rson[26], val[26], cnt;
void add(char c) {
int num = c - 'A';
if (cnt == 0) {
cnt ++;
val[cnt] = num;
lson[cnt] = rson[cnt] = -1;
return;
}
int p = 1;
while (true) {
if (num < val[p]) {
if (lson[p] != -1) p = lson[p];
else {
lson[p] = ++cnt;
val[cnt] = num;
lson[cnt] = rson[cnt] = -1;
break;
}
}
else if (num >val[p]) { // num > val[p]
if (rson[p] != -1) p = rson[p];
else {
rson[p] = ++cnt;
val[cnt] = num;
lson[cnt] = rson[cnt] = -1;
break;
}
}
// num == val[p] 不管
}
}
void dfs(int p) {
putchar('A' + val[p]);
if (lson[p] != -1) dfs(lson[p]);
if (rson[p] != -1) dfs(rson[p]);
}
void handle() {
cnt = 0;
while (!stk.empty()) {
string s = stk.top();
stk.pop();
int len = s.length();
for (int i = 0; i < len; i ++) add(s[i]);
}
if (!cnt) puts("");
else {
dfs(1);
puts("");
}
}
int main() {
while (cin >> s) {
if (!isupper(s[0])) {
handle();
if (s[0] == '$') break;
}
else {
stk.push(s);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator