这个题目是模拟,256步操作,但超过256步时一定是死循环,否则按照题目模拟即可。学会strcmp的用法。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
using namespace std;
const int maxn = 34;
struct node
{
char s[10];
int k,v;
}a[10005];
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%s%d",a[i].s,&a[i].v);
if(strcmp(a[i].s,"add")!=0){
scanf("%d",&a[i].k);
}
}
int j=1,flag=0,vis[10010]={0},r=0;
while(1){
vis[j]++;
if(strcmp(a[j].s,"add")==0){
r=(r+a[j].v)%256;
j++;
}
else if(!strcmp(a[j].s,"bgt")){
if(r>a[j].v){
j=a[j].k;
}
else {
j++;
}
}
else if(!strcmp(a[j].s,"blt")){
if(r<a[j].v){
j=a[j].k;
}
else {
j++;
}
}
else if(!strcmp(a[j].s,"bne")){
if(r!=a[j].v){
j=a[j].k;
}
else{
j++;
}
}
else if(!strcmp(a[j].s,"beq")){
if(r==a[j].v){
j=a[j].k;
}
else {
j++;
}
}
if(j>n){
// cout<<j<<endl;
flag=1;
break;
}
if(vis[j]>=256){
break;
}
}
if(flag){printf("Yes\n");}
else {printf("No\n");}
}
}
return 0;
}