자라는 개발자/문제풀이

백준 c++ 13238 Bitcoin investment

자란다 2022. 9. 26. 16:07
728x90
반응형

13238 Bitcoin investment

 

문제풀이

#include <iostream>
#include <vector>

int num;
using namespace std;

int main(void)
{
    cin >> num;
    vector<int> v(num);
    for(int i=0;i<num;i++)
        cin >> v[i];
    if(num==1)
    {
        cout << "0";
        return 0;
    }
    int tmp=0;
    for(int i=0;i<num;i++)
        for(int j=i+1;j<num;j++)
        {
            if(v[i]<v[j] && (tmp<v[j]-v[i]))
                tmp = v[j]-v[i];
        }
    cout << tmp;
}

값을비교하여 최대값인경우 tmp에 넣어준뒤, 출력했다.

728x90
반응형

'자라는 개발자 > 문제풀이' 카테고리의 다른 글

leetcode 350. Intersection of Two Arrays II  (0) 2022.11.13
leetcode 242. Valid Anagram  (0) 2022.11.13
백준 c++ 1817 짐 챙기는 숌  (0) 2022.08.23
백준 c++ 16460 Cupid  (0) 2022.08.21
백준 c++ 15312 이름 궁합  (0) 2022.08.17