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

改了一下,还能更短吗?

Posted by KatrineYang at 2016-07-11 11:00:09 on Problem 1049
In Reply To:好吧呀,是洞。过了,附代妈。 Posted by:KatrineYang at 2016-07-11 10:47:42
#include <iostream>
#include <string>
using namespace std;
int N(int c){
	if(c>='0'&&c<='9') return c-'0';
	return c-'A'+10;
}
int C(int i){
	if(i<10) return i+'0';
	return i-10+'A';
}
void p(string &s){
	int A=0,B=0,P=0;
	while(s[P]!='8'){
		int c=N(s[P]);
		int a=N(s[P+1])*16+N(s[P+2]);
		switch(c){
		case 0:{
			A=N(s[a]);
			P+=3;
			break;}
		case 1:{
			s[a]=C(A);
			P+=3;
			break;}
		case 2:{
			int t=A;
			A=B;
			B=t;
			P++;
			break;}
		case 3:{
			int r=A+B;
			A=r%16;
			B=r/16;
			P++;
			break;}
		case 4:{
			A=(A+1)%16;
			P++;
			break;}
		case 5:{
			A=(A+15)%16;
			P++;
			break;}
		case 6:{
			if(!A)P=a;
			else P+=3;
			break;}
		case 7:{
			P=a;
			break;}
		}
	}
}
int main() {
	while(1){
		string s;
		cin>>s;
		if(s[0]=='8') return 0;
		p(s);
		cout<<s<<endl;
	}
	return 0;
}

Followed by:

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

Content:

Home Page   Go Back  To top


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