알고리즘/백준

백준 6325 Definite Values

등반 2021. 12. 27. 00:33

https://www.acmicpc.net/problem/6325

 

6325번: Definite Values

Assume that before the execution of the given program part, variable a has some definite value, while all other variables are undefined. You have to print the names of the variables which have a definite value after the execution of the program part. More

www.acmicpc.net

해설

변수를 선언하고 초기화를 하지 않으면 이상한 값이 들어가기 때문에 값을 특정할 수 없다.

1. a의 값은 특정할 수 있는 경우에

2. 입력 문자열의 초기화 과정을 거친 후

3. 값을 특정할 수 있는 변수의 갯수를 찾는다.

 

※주의 :

1. a의 값은 기본적으로 특정 가능하다.

2. 특정할 수 없는 값을 a에 대입하는 경우, a도 특정할 수 없다.

#include <iostream>
#define fio cin.tie(0)->sync_with_stdio(0)
using namespace std;

#include <set>

int main(){
    fio;
    int N;
    int TC = 1;
    while(1){
        cin >> N;
        if(N == 0) break;
        //
        set<char> set_;
        set_.insert('a');
        for(int i=0; i < N; i++){
            char left, eq, right;
            cin >> left >> eq >> right;
            if(set_.find(right) != set_.end()){//있는 값을 넣기
                set_.insert(left);
            }else{//없는 값 넣기 >> 이상한 값
                set_.erase(left);
            }
        }
        cout << "Program #" << TC <<'\n';
        if(set_.size() != 0){
        //
            set<char>::iterator iter;
            for(iter = set_.begin(); iter != set_.end(); iter++){
                cout << *iter <<' ';
            }
        }else{
            cout << "none";
        }
        //
        cout <<"\n\n";
        TC++;
    }
    return 0;
}

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

백준 8641 Sklep  (0) 2021.12.27
백준 6973 Dynamic Dictionary Coding  (0) 2021.12.27
백준 5608 問題 2  (0) 2021.12.27
백준 4775 Spelling Be  (0) 2021.12.27
백준 4351 Hay Points  (0) 2021.12.27