알고리즘/백준[BOJ] 오답노트

C++ 무한루프 탈출 break continue - 백준 알고리즘 오답노트 10845

플라즈밍 2019. 3. 2. 14:12
반응형

C++ 무한루프 탈출 break continue - 백준 알고리즘 오답노트 10845


while(){  }  에서

 처음으로 돌아가 실행- > continue 

 반복문 탈출 -> break;


do{ }while(); 에서

 처음으로 돌아가 실행 -> break;

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
//10845
 
#include<string>
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int cases; cin>> cases; queue<int> q;
    while(cases--){
        string command; cin>>command;
        if(command == "push"){ int val; cin>>val; q.push(val);  }
        if(command == "pop"){ if(q.empty()) {cout<<-1<<"\n"continue;} int val = q.front(); q.pop(); cout<<val<<"\n";         }
        if(command == "size"){ cout<<q.size()<<"\n";}
        if(command == "empty"){ cout<<q.empty()<<"\n";}
        if(command == "front"){ if(q.empty()) {cout<<-1<<"\n"continue;} cout<<q.front()<<"\n";}
        if(command == "back"){ if(q.empty()) {cout<<-1<<"\n"continue;} cout<<q.back()<<"\n";}        
        
        
    }
    return 0;
}
 
//FB1. 무한 반복문에서의 break 와 continue의 의미차이 
cs


반응형