백준 10093. 숫자

Soni·2024년 8월 12일
#include <bits/stdc++.h>
using namespace std;

int main(void){
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  long long a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  if (a == b || b - a == 1) cout << 0;
  else {
  	cout << b - a - 1 << '\n';
    for (long long i = a + 1; i < b; i++)
    	cout << i << " ";
  }
  return 0;
}

왜 if - if - else 구조인지 생각하기
만약 if - else if - else의 구조라면 a > b인 경우 swap만 하고 연산을 하지 않는다.

profile
Cloud, DevOps

0개의 댓글