RT WA on 10
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
#define int long long
#define f(W, X, Y, Z) for(int W = X; W <= Y; W += Z)
#define F(W, X, Y, Z) for(int W = X; W >= Y; W -= Z)
#define debug puts("QAQ")
namespace SyxQwQ{
inline int qwq(){
return 0;
}
struct _{
string s;
int line;
bool willend, willgo, willif, willplus;
int gotowhere, ifvalue, ifgoto, plusvalue;
char ifchar, pluschar;
}p[114];
bool cmp(_ a, _ b){
return a.line < b.line;
}
map<int, int> a;
map<char, int> z;
int doingtime = 0, nowline;
inline int getnowz(int &i){
//debug;
int x = 0;
while(p[nowline].s[i] > '9' || p[nowline].s[i] < '0') ++i;
while(p[nowline].s[i] <= '9' && p[nowline].s[i] >= '0'){
x = x * 10 + (p[nowline].s[i] - '0');
++i;
}
//cout << x << " ";
return x;
}
inline void func(){
p[nowline].s += " ";
int l = p[nowline].s.size();
for(int i = 0; i < l; i++){
if(p[nowline].s[i]=='E' && p[nowline].s[i+1]=='N' && p[nowline].s[i+2]=='D'){
//printf("1\n");
p[nowline].willend = 1;
return ;
}else if(p[nowline].s[i] == 'G' && p[nowline].s[i+1] == 'O'){
//printf("2\n");
p[nowline].willgo = 1;
p[nowline].gotowhere = a[getnowz(i)];
return ;
}else if(p[nowline].s[i] == 'I' && p[nowline].s[i+1] == 'F'){
//printf("3\n");
p[nowline].willif = 1;
i += 3;
p[nowline].ifchar = p[nowline].s[i];
i += 2;
p[nowline].ifvalue = getnowz(i);
p[nowline].ifgoto = getnowz(i);
return ;
}
else if(p[nowline].s[i] >= 'A' && p[nowline].s[i] <= 'Z'){
//printf("4\n");
p[nowline].pluschar = p[nowline].s[i];
++i;
if(p[nowline].s[i] == '?') continue;
else if(p[nowline].s[i] == '+'){
p[nowline].willplus = 1;
p[nowline].plusvalue = getnowz(i);
++i;
}
}
}
return ;
}
inline void check(){
doingtime++;
if(doingtime > 5000000){
printf("-1\n");
exit(0);
}
if(p[nowline].willend){
printf("%lld\n", doingtime);
exit(0);
}else if(p[nowline].willplus){
z[p[nowline].pluschar] += p[nowline].plusvalue;
}else if(p[nowline].willgo){
nowline = p[nowline].gotowhere;
return ;
}else if(p[nowline].willif){
//if('A' == p[nowline].ifchar) printf("%lld\n", p[nowline].ifgoto);
if(z[p[nowline].ifchar] == p[nowline].ifvalue){
nowline = a[p[nowline].ifgoto];
return ;
}
}
nowline++;
}
inline int main(){
int len = 0;
while(cin >> p[++len].line){
getchar();
getline(cin, p[len].s);
}
--len;
sort(p + 1, p + 1 + len, cmp);
f(j, 1, len, 1){
a[p[j].line] = j;
nowline = j;
func();
}
nowline = 1;
while(1){
//printf("%lld\n", z['A']);
check();
}
//printf("%lld\n", doingtime);
return qwq();
}
}
signed main(){
SyxQwQ::main();
return 0;
}
10 数据
100 IF A=9999 GO 2700
110 A+1
120 GO 2800
200 IF B=9999 GO 2700
210 B+1
220 GO 2800
300 IF C=9999 GO 2700
310 C+1
320 GO 2800
400 IF D=9999 GO 2700
410 D+1
420 GO 2800
500 IF E=9999 GO 2700
510 E+1
520 GO 2800
600 IF F=9999 GO 2700
610 F+1
620 GO 2800
700 IF G=9999 GO 2700
710 G+1
720 GO 2800
800 IF H=9999 GO 2700
810 H+1
820 GO 2800
900 IF I=9999 GO 2700
910 I+1
920 GO 2800
1000 IF J=9999 GO 2700
1010 J+1
1020 GO 2800
1100 IF K=9999 GO 2700
1110 K+3
1120 GO 2800
1200 IF L=9999 GO 2700
1210 L+1
1220 GO 2800
1300 IF M=9999 GO 2700
1310 M+1
1320 GO 2800
1400 IF N=9999 GO 2700
1410 N+1
1420 GO 2800
1500 IF O=9999 GO 2700
1510 O+1
1520 GO 2800
1600 IF P=9999 GO 2700
1610 P+1
1620 GO 2800
1700 IF Q=9999 GO 2700
1710 Q+1
1720 GO 2800
1800 IF R=9999 GO 2700
1810 R+1
1820 GO 2800
1900 IF S=9999 GO 2700
1910 S+1
1920 GO 2800
2000 IF T=9999 GO 2700
2010 T+1
2020 GO 2800
2700 Z+1
2701 IF Z=0 GO 100
2702 IF Z=1 GO 200
2703 IF Z=2 GO 300
2704 IF Z=3 GO 400
2705 IF Z=4 GO 500
2706 IF Z=5 GO 600
2707 IF Z=6 GO 700
2708 IF Z=7 GO 800
2709 IF Z=8 GO 900
2710 IF Z=9 GO 1000
2711 IF Z=10 GO 1100
2712 IF Z=11 GO 1200
2713 IF Z=12 GO 1300
2714 IF Z=13 GO 1400
2715 IF Z=14 GO 1500
2716 IF Z=15 GO 1600
2717 IF Z=16 GO 1700
2718 IF Z=17 GO 1800
2719 IF Z=18 GO 1900
2720 IF Z=19 GO 2000
2799 END
2800 IF U=1 GO 2720
2810 IF U=1 GO 520
2820 IF Y=1 GO 400
2830 IF V=1 GO 2719
2840 IF V=1 GO 1510
2850 IF X=1 GO 100
2860 IF V=1 GO 110
2870 IF U=1 GO 2711
2880 IF V=1 GO 2800
2890 IF W=1 GO 710
2900 IF U=1 GO 820
2910 IF W=1 GO 2715
2920 IF U=1 GO 1010
2930 IF Y=1 GO 920
2940 IF U=1 GO 1100
2950 IF V=1 GO 2799
2901 GO 2701
3000 END
然后正确输出 4926444,我的答案是 40342