백준

2460 지능형기자 2

불타는강정 2019. 10. 25. 20:13

전에도 이 문제 풀었는데 차이가 뭐지? 몰라서 그냥 전처럼 쉽게 풀었다.

그래도 나름 for 루프 안에 쓰이는 건 for문 안에 변수 선언하고 값 변하면 안되는 부분은 밖에 선언했다. 

#include <iostream>

int main() {
    int max = 0;
    int now = 0;
    
    for(int i = 0; i < 10; i++){
        int in, out;
        scanf("%d %d", &out, &in);
        now = in - out + now;
        if(now > max)
            max = now;
    }
    
    printf("%d", max);
    return 0;
}

 

오랜만에 풀었다