zhang_kevin @ 2023-02-01 20:45:52
只过了#4,其他RE
by zhang_kevin @ 2023-02-01 20:46:02
// Author: zhang_kevin
// Problem Name: P2830 写程序
// URL: https://www.luogu.com.cn/problem/P2830
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// Created: 2023-02-01 18:16:20
#include<bits/stdc++.h>
using namespace std;
struct arr{
int len;
int val[101];
};
map<string, arr> g;
inline int getType(string s){
if(s.substr(0, 5) == "cout ") return 3;
if(s.substr(0, 4) == "int ") return 1;
return 2;
}
inline void get(string s, string &name, int &pos){
if(isdigit(s[s.size()-1])){
name = "114514_NON_NAME";
pos = stoi(s);
return;
}
if(isdigit(s[s.size()-2])){
s.pop_back();
name = "";
string ssz = "";
int l = 0;
while(s[l] != '[') name += s[l], l++;
for(int i = l + 1; i < (int)s.size(); i++){
ssz += s[i];
}
pos = stoi(ssz);
return;
}
s.pop_back();
string realname = "";
int l = 0;
while(s[l] != '[') realname += s[l], l++;
s = s.substr(l+1, s.size() - l - 1);
int realpos = 0;
get(s, name, pos);
if(pos > g[name].len - 1) puts("-1"), exit(0);
realpos = g[name].val[pos];
name = realname;
pos = realpos;
return;
}
int main(){
string s;
while(getline(cin, s)){
int type = getType(s);
if(type == 1){
int len = 0;
for(int i = 4; s[i] != '['; i++) len++;
string name = s.substr(4, len);
while(s[s.size()-1] == '\r' || s[s.size()-1] == '\n'){
s.pop_back();
}
string ssz = s.substr(5+len, s.size()-(5+len)-1);
int isz = stoi(ssz);
g[name].len = isz;
}else if(type == 3){
s = s.substr(1, s.size()-1);
int len = 0;
for(int i = 4; s[i] != '['; i++) len++;
string name = s.substr(4, len);
while(s[s.size()-1] == '\r' || s[s.size()-1] == '\n'){
s.pop_back();
}
string ssz = s.substr(5+len, s.size()-(5+len)-1);
int isz = stoi(ssz);
if(isz > g[name].len - 1) puts("-1"), exit(0);
cout << g[name].val[isz] << endl;
}else{
int space = s.find(32);
string s1 = s.substr(0, space);
string s2 = s.substr(space+1, s.size()-space-1);
string name1, name2;
int pos1, pos2;
get(s1, name1, pos1);
get(s2, name2, pos2);
if(name2 == "114514_NON_NAME"){
if(pos1 > g[name1].len - 1){
puts("-1");
exit(0);
}
g[name1].val[pos1] = pos2;
continue;
}
if(pos1 > g[name1].len - 1 || pos2 > g[name2].len - 1){
puts("-1");
exit(0);
}
g[name1].val[pos1] = g[name2].val[pos2];
}
}
return 0;
}
by yszkddzyh @ 2023-02-01 20:51:47
@zhang_kevin RE的提示是不是“Runtime Error. Received signal 6: Aborted / IOT trap.”
by zhang_kevin @ 2023-02-01 20:52:33
@yszkddzyh 对
by yszkddzyh @ 2023-02-01 20:53:48
@zhang_kevin 应该是洛谷评测机出锅了,我前天试了也是这样,要把 string
改成字符数组。