티스토리 뷰

알고리즘/백준(BOJ)

백준 - 3568 iSharp

시나모온 2020. 6. 21. 23:08

문제 링크입니다 : https://www.acmicpc.net/problem/3568

 

3568번: iSharp

문제 선영이는 C, C++, Java와는 다른 아주 세련된 언어를 만들었다. 선영이는 이 아름답고 예술적인 언어의 이름을 i#으로 정했다. i#은 기본 변수형과 배열([]), 참조(&), 포인터(*)를 제공한다. 배열

www.acmicpc.net

 

 

 

문자열 관련 문제이다. 구현 문제!

 

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

using namespace std;

int main() {
    string type;
    cin >> type;

    cin.ignore();
    string str;
    getline(cin, str);
    

    string temp = "";
    string val = "";

    for(int i = 0; i < str.size(); i++) {
        char c = str[i];
        if(c == ' ') continue;
        if(c == ',' || c == ';') {
            reverse(temp.begin(), temp.end());
            for(int j = 0; j < temp.size(); j++) {
                if(temp[j] == '[') {
                    temp[j] = ']';
                } else if(temp[j] == ']') {
                    temp[j] = '[';
                }
            }
            cout << type << temp << ' ' << val << ";\n";
            temp = "";
            val = "";
            continue;
        }

        if(isalpha(c)) {
            val += c;
        } else {
            temp += c;
        }
    }


    return 0;
}

 

 

 

개발 환경 : vscode

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

 

'알고리즘 > 백준(BOJ)' 카테고리의 다른 글

백준 - 11404 플로이드  (0) 2020.06.21
백준 - 2037 문자메시지  (0) 2020.06.21
백준 - 1174 줄어드는 숫자  (0) 2020.06.16
백준 - 11657 타임머신  (0) 2020.06.16
백준 - 9370 미확인 도착지  (0) 2020.06.12
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함