Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
好吧呀,是洞。过了,附代妈。In Reply To:两个寄存器的初始值是多少??? Posted by:KatrineYang at 2016-07-11 09:58:55 #include <iostream> #include <string> using namespace std; int toNum(char c){ if(c >= '0' && c <= '9') return c-'0'; else return c-'A'+10; } int toChar(int i){ if(i < 10) return (char)(i+'0'); else return (char)(i-10+'A'); } void process(string &s){ int A = 0, B = 0; int pos = 0; while(s[pos] != '8'){ int c = toNum(s[pos]); int addr; switch(c){ case 0:{ addr = toNum(s[pos+1])*16+toNum(s[pos+2]); A = toNum(s[addr]); pos+=3; break;} case 1:{ addr = toNum(s[pos+1])*16+toNum(s[pos+2]); s[addr] = toChar(A); pos+=3; break;} case 2:{ int temp = A; A = B; B = temp; pos++; break;} case 3:{ int res = A + B; A = res%16; B = res/16; pos++; break;} case 4:{ A = (A+1)%16; pos++; break;} case 5:{ A = (A+15)%16; pos++; break;} case 6:{ addr = toNum(s[pos+1])*16+toNum(s[pos+2]); if(A == 0) pos = addr; else pos+=3; break;} case 7:{ addr = toNum(s[pos+1])*16+toNum(s[pos+2]); pos = addr; break;} default:{ pos++; break;} } } } int main() { while(1){ string s; cin >> s; if(s.length() != 256 || s[0] == '8') return 0; process(s); cout << s << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator