ACM A. The Good, the Bad and the Ugly

/*
A. The Good, the Bad and the Ugly
Time limit: 0.5 second
Memory limit: 256 MB
Everyone knows that computer see integers not in the same way as humans do. Instead of digits from 0 to 9 they use digits from 0 to 255. For example, the integer 1 000 000 can by represented by a computer with three digits 15, 66, 64 (let’s denote it as 15;66;64), because 15· 2562 + 66· 256 + 64 = 1 000 000. On top of that, integers in computers have a fixed size. In this problem the size of an integer is always 4 digits, so the integer 1 000 000 will be represented as 0;15;66;64. Computers use this exact format to communicate with each other.
This system may seem strange, but it works. Or, it used to work, until an evil genius reversed the order of digits in half of the computers! These computers now interpret 0;15;66;64 not as 1 000 000 but as 1 078 071 040 (64· 2563 + 66· 2562 + 15· 256 + 0 = 1 078 071 040). No one knows how to fix it, so the computers that are left untouched are now called “good”, and other computers are called “bad”. In order for “good” and “bad” computers to communicate, the integers that are read incorrectly must be translated into correct integers.
For example, let A and B be two computers of opposite types. Let’s say the computer A wants to send the computer B a non-negative integer not exceeding 4 294 967 295. The computer A writes this integer down with four digits from 0 to 255 and sends them to the computer B. Computer B reads the received digits as v, which doesn’t necessary match the integer the computer A was trying to send.
Write a program that would help a “good” or a “bad” computer B determine, what integer the computer A of the opposite type tried to send.
Input
The first line contains one word, denoting the type of the computer A, which sent the integer: “GOOD” (without quotes), if the computer is “good”, and “BAD” (without quotes), if the computer is “bad”.
The second line contains a non-negative integer v that the computer B received (0 ≤ v ≤ 4 294 967 295).
Output
In the only line output the non-negative integer that the computer A sent.
Samples
input	output
 
输入GOOD
16777216
输出1
输入BAD
1000
输出3892510720
样品
输入	输出
良好
16777216
1个
坏
1000
3892510720
Notes
In the first example the integer 16 777 216 = 1·2563 + 0·2562 + 0·256 + 0 was read by the “bad” computer B from digits 0;0;0;1. The “good” computer A wrote the integer 0·2563 + 0·2562 + 0·256 + 1 = 1.
In the second example the integer 1000 = 0·2563 + 0·2562 + 3·256 + 232 was read by the “good” computer A from digits 0;0;3;232. The “bad” computer B wrote the integer 232·2563 + 3·2562 + 0·256 + 0 = 3 892 510 720.
Problem Author: Aidar Islamov
Printable version
输入一个good或者bad 然后再输入B电脑的数字
输出A电脑输入的数字
A电脑的数字经过了四个数字回文交换位置,然后再都*256最后和再*一次256 
*/ 
long long numb[5];
#include<stdio.h>
int AAA(int a){
    
    		//给一个数字进去然后÷256再把各个位置的数字交换回来再*256 
	a=a/256;
	int j=256;
	numb[1]=a/j/j%256;		//64
	numb[2]=a/j%256;		//66
	numb[3]=a%256;			//15		
	numb[4]=a/j/j/j%256;	//0
	return numb[4]*j*j*j+numb[3]*j*j+numb[2]*j+numb[1];
}
long long BBB(int a){
    
    		//给一个数字进去然后÷256再把各个位置的数字交换回来再*256 
	int j=256;
	numb[1]=a/j/j/j%256;	//0
	numb[2]=a/j/j%256;		//64
	numb[3]=a/j%256;		//66
	numb[4]=a%256;			//232	
	return numb[4]*j*j*j+numb[3]*j*j+numb[2]*j+numb[1];
}
int main()
{
    
    
	int n;
	char q[10]; 
	
	scanf("%s%d",&q,&n);
	if(q[0]=='G')
	{
    
    
		printf("%d",AAA(n));	//A电脑为good的时候 
	}
	else
	{
    
    
		printf("%lld",BBB(n));	//B电脑为bad的时候 
	}
/*这应该还有更好的算法了    为啥百度不出来了*/

} 

猜你喜欢

转载自blog.csdn.net/jhfgjhg1/article/details/108984641
今日推荐