Bomb Kirby Running
Cat Life - GT-K
1928번 Base64 Decoder

2023. 4. 16. 23:16SWEA

Problem Solving - Level 2 - Base64 Decoder

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PR4DKAG0DFAUq&categoryId=AV5PR4DKAG0DFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=3

#include <iostream>
using namespace std;
char decoding(char temp)
{
    if('A'<=temp&temp<='Z')
    {
    	temp = temp - 'A';
    }
    
    else if('a'<=temp&temp<='z')
    {
    	temp = temp - 'a' + 26;
    }
    
    else if('0'<=temp&temp<='9')
    {
    	temp = temp - '0' + 52;
    }
    
    else if(temp=='+')
    {
        temp=62;
    }
    
    else if(temp=='/')
    {
        temp=63;
    }
    return temp;
}

int main()
{
	int T;
    cin>>T;
    
    for(int i=1;i<=T;i++)
    {
        string str,encoding="";
        char temp;
        cin>>str;
        
        for(int j=0;j<str.length()/4;j++)
        {
            temp=decoding(str.at(j*4))*4+decoding(str.at(j*4+1))/16;
            encoding+=temp;
            temp=(decoding(str.at(j*4+1))%16)*16+(decoding(str.at(j*4+2))/4);
            encoding+=temp;
            temp=(decoding(str.at(j*4+2))%4)*64+decoding(str.at(j*4+3));
            encoding+=temp;
        }
        cout<<"#"<<i<<" "<<encoding<<endl;
    }
    return 0;
}

'SWEA' 카테고리의 다른 글

1288번 새로운 불면증 치료법  (0) 2023.04.16
1285번 아름이의 돌 던지기  (0) 2023.04.16
1284번 수도 요금 경쟁  (0) 2023.04.16
1204번 최빈수 구하기  (0) 2023.04.16
2072번 홀수만 더하기  (0) 2023.03.23