
unsigned int 타입은 4 bytes를 할당하는데, 각 byte를 Reverse하는게 문제의 목표이다.
char 타입은 1 byte를 할당한다. 따라서 unsigned int 타입을 char[4] 배열로
캐스팅을 하면 쉽게 문제를 풀 수 있다.
#include <iostream>
using namespace std;
typedef struct{
char byte_0;
char byte_1;
char byte_2;
char byte_3;
} Byte;
unsigned int convert(unsigned int param){
unsigned int result;
Byte *bytesParam = (Byte*) ¶m;
Byte *bytesResult = (Byte*) &result;
bytesResult->byte_0 = bytesParam->byte_3;
bytesResult->byte_1 = bytesParam->byte_2;
bytesResult->byte_2 = bytesParam->byte_1;
bytesResult->byte_3 = bytesParam->byte_0;
return result;
}
int main(){
int c;
cin >> c;
if((c<1) || (c>10000))
cerr << "invalid input" << endl;
unsigned int *inputs = new unsigned int[c];
for(int i=0; i<c; i++){
cin >> inputs[i];
}
for(int i=0; i<c; i++){
cout << convert(inputs[i]) << endl;
}
}