为什么代码疯狂RE
  • 板块学术版
  • 楼主good101202abc
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/7/5 15:36
  • 上次更新2024/7/5 16:54:52
查看原帖
为什么代码疯狂RE
1280769
good101202abc楼主2024/7/5 15:36

去UVA上交了好几次,每次都是Runtime Error,上Udebug上测样例全都通过了,求指教!!!!

#include <bits/stdc++.h>
#define maxn 105

using i64 = long long;
using namespace std;

char table[maxn][10], words[maxn][15], morse[maxn][maxn];
char a, codes[maxn][maxn];
int x = 0, y = 0;

void solve() {
	for (int i = 0; i < x; i++) {
		int cnt = 0;
		for (int j = 0; j < y; j++) {
			if (!strcmp(morse[i], codes[j])) {
				if (!cnt) cout << words[j];
				else if (cnt == 1) cout << "!";
				else break;
				cnt++;
			}
		}
		if (!cnt) {
			cnt = maxn; int p;
			for (int j = 0; j < y; j++) {
				int flag = 0;
				int m = strlen(morse[i]), n = strlen(codes[j]);
				for (int k = 0; k < min(m, n); k++) {
					if (codes[j][k] != morse[i][k]) {
						flag = 1;
						break;
					}
				}
				if (!flag) 
					if (abs(m - n) < cnt) {
						cnt = abs(m - n);
						p = j;
					}
			}
			cout << words[p] << "?";
		}
		cout << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	while (cin >> a && a != '*') {
		cin >> table[(int)a];
	}
	while (cin >> words[y] && words[y][0] != '*') {
		int len = strlen(words[y]);
		for (int k = 0; k < len; k++) {
			strcat(codes[y], table[(int)words[y][k]]);
		}
		y++;
	}
	while (cin >> morse[x] && morse[x][0] != '*') x++;
	solve();
	return 0;
}

洛谷题目链接

2024/7/5 15:36
加载中...