Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
 User ID: Password:
Register

## pc的值必须对32取模

Posted by 200842128 at 2012-02-14 21:18:57 on Problem 2410
```#include <iostream>
#include <stdio.h>
using namespace std;

unsigned char ins[32], accu, pc;
char str[10];

unsigned char getValue(char *ins)
{
unsigned char res(0);
for(int i(0); i<8; ++i) res = res * 2 + ins[i] - '0';
return res;
}

int main()
{
bool halt;
int type, value;

while(scanf("%s", str) != EOF)
{
ins[0] = getValue(str);
for(int i(1); i<32; ++i) scanf("%s", str), ins[i] = getValue(str);

halt = false;
pc = accu = 0;

while(!halt)
{
type = ins[pc] >> 5;
value = ins[pc] % 32;

switch(type)
{
case 0:
ins[value] = accu;
pc = (pc + 1) % 32;
break;

case 1:
accu = ins[value];
pc = (pc + 1) % 32;
break;

case 2:
if(!accu) pc = value;
else pc = (pc + 1) % 32;
break;

case 3:
pc = (pc + 1) % 32;
break;

case 4:
--accu;
pc = (pc + 1) % 32;
break;

case 5:
++accu;
pc = (pc + 1) % 32;
break;

case 6:
pc = ins[pc] % 32;
break;

case 7:
halt = true;
break;
}
}

for(int i(7); i>=0; --i)
printf("%d", (accu >> i) & 1);
printf("\n");
}

system("pause");
return 0;
}```

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator