problem 1098
来源:互联网 发布:php 抓取搜狗微信文章 编辑:程序博客网 时间:2024/06/06 02:47
TMD,搞了快一个半小时了!位运算很不熟练的说。。
Accepted 1098 C++ 00:00.00 384K
#include<stdio.h>
#define sz(a) (sizeof(a) * 8)
char memory[32];
void print(char accu)
{
for(int i = 7; i >= 0; i--)
if((accu & (1 << i)) == 0) printf("0");
else printf("1");
}
void solve()
{
char pc = 0,opt,accu = 0;
while(1)
{
opt = ((memory[pc] & 0xe0) >> 5) & 0x07;
switch(opt)
{
case 0:
memory[memory[pc] & 0x1f] = accu;
break;
case 1:
accu = memory[memory[pc] & 0x1f];
break;
case 2:
if((accu & 0xff)== 0)
{
pc = memory[pc] & 0x1f;
continue;
}
break;
case 4: --accu; break;
case 5: ++accu; break;
case 6: pc = memory[pc] & 0x1f; continue;
case 7: print(accu); return;
default: break;
}
pc = ++pc % 32;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1098.txt","r",stdin);
#endif
while(1)
{
for(int i = 0; i < 32; i++)
{
char temp[9];
if(scanf("%s",temp) == EOF)
return 0;
memory[i] = 0;
for(int j = 0; temp[j]; j++)
if(temp[j] == '0') continue;
else memory[i] |= (1 << (7 - j));
}
solve();
printf("/n");
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
#define sz(a) (sizeof(a) * 8)
char memory[32];
void print(char accu)
{
for(int i = 7; i >= 0; i--)
if((accu & (1 << i)) == 0) printf("0");
else printf("1");
}
void solve()
{
char pc = 0,opt,accu = 0;
while(1)
{
opt = ((memory[pc] & 0xe0) >> 5) & 0x07;
switch(opt)
{
case 0:
memory[memory[pc] & 0x1f] = accu;
break;
case 1:
accu = memory[memory[pc] & 0x1f];
break;
case 2:
if((accu & 0xff)== 0)
{
pc = memory[pc] & 0x1f;
continue;
}
break;
case 4: --accu; break;
case 5: ++accu; break;
case 6: pc = memory[pc] & 0x1f; continue;
case 7: print(accu); return;
default: break;
}
pc = ++pc % 32;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1098.txt","r",stdin);
#endif
while(1)
{
for(int i = 0; i < 32; i++)
{
char temp[9];
if(scanf("%s",temp) == EOF)
return 0;
memory[i] = 0;
for(int j = 0; temp[j]; j++)
if(temp[j] == '0') continue;
else memory[i] |= (1 << (7 - j));
}
solve();
printf("/n");
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
- problem 1098
- Problem 1098 - 城镇距离
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- 有人说Java比C++快?
- 一个月赚5万美元--国产共享软件开发者周奕
- 开张
- .net阅读心得(一)
- 学习WPF(第一天)-补记
- problem 1098
- GridView 实现自定义分页、排序、查询、添加、编辑、多选删除、导出、突出显示等常见应用实现(cs)
- ValidatorCalloutExtender
- 演练VC中的COMMON一族(转贴)之一 选择自 happyparrot 的 Blog
- 好啊,同志们!
- C#编码标准--编码习惯
- web.cofig的设置(收集中)
- Csdn我来了!
- JTable 的TableModel (使用TMF框架只用一行代码)