Created
November 15, 2016 08:26
-
-
Save splitline/6b81ae6dd126d2b57c0622a4f133e8ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
int mem[65540]={0}; | |
int main(){ | |
int N; | |
while(~scanf("%d",&N)){ | |
memset(mem,0,sizeof(mem)); | |
int k,addr,val_n; | |
char cmd[5]={0},type[10]={0},val[1000]={0}; | |
scanf("%d",&k); | |
int max=-1; | |
for(int i=0;i<k;i++){ | |
scanf("%s%d%s",cmd,&addr,type); | |
if(addr>max)max=addr; | |
if(addr>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
if(!strcmp(cmd,"Set")){ | |
if(!strcmp(type,"String")){ | |
scanf(" "); | |
gets(val); | |
if(addr+strlen(val)>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
for(int j=addr;j<strlen(val)+addr;j++){ | |
mem[j]=(int)val[j-addr]; | |
} | |
mem[strlen(val)+addr]=0; | |
} | |
if(!strcmp(type,"char")){ | |
if(addr>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
scanf("%d",&mem[addr]); | |
// mem[addr]=getchar(); | |
} | |
if(!strcmp(type,"int")){ | |
if(addr+4>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
scanf("%d",&val_n); | |
for(int i=addr;i<addr+4;i++){ | |
mem[i]=val_n%256; | |
val_n/=256; | |
} | |
} | |
if(!strcmp(type,"short")){ | |
if(addr+2>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
scanf("%d",&val_n); | |
for(int j=addr;j<addr+2;j++){ | |
mem[j]=val_n%256; | |
val_n/=256; | |
} | |
} | |
} | |
if(!strcmp(cmd,"Get")){ | |
if(!strcmp(type,"String")){ | |
if(addr>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
for(int j=addr;mem[j]!=0||j<=max;j++){ | |
printf("%c",mem[j]); | |
} | |
printf("\n"); | |
} | |
if(!strcmp(type,"char")){ | |
if(addr>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
printf("%c\n",mem[addr]); | |
} | |
if(!strcmp(type,"int")){ | |
if(addr+4>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
int tmp=0x00; | |
tmp=mem[addr]+mem[addr+1]*0x100+mem[addr+2]*0x100*0x100+mem[addr+3]*0x100*0x100*0x100; | |
printf("%d\n",tmp); | |
} | |
if(!strcmp(type,"short")){ | |
if(addr+2>N){ | |
printf("Violation Access.\n"); | |
continue; | |
} | |
int tmp=0x00; | |
tmp=mem[addr]+mem[addr+1]*0x100; | |
printf("%d\n",tmp); | |
} | |
} | |
//printf("\n"); | |
//for(int i=0;i<20;i++)printf("%x;",mem[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment