백준 algorithm

백준 8974 - 희주의 수학시험

cosmohoo 2019. 9. 11. 18:37
반응형

문제 설명 

for문을 이용해 배열을 생성하면 간단하게 할 수 있다. 
문제를 잘못이해해 두번이나 틀렸다.......ㅠ

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	vector<int> arr;
	for (int i = 1; i <= 1000; i++)
	{
		for (int j = 0; j < i; j++)
		{
			arr.push_back(i);
		}
	}
	int start,end = 0;
	int val = 0;
	cin >> start>>end;
	for (int s = start; s <= end; s++)
	{
		val += arr[s-1];
	}
	cout << val;
	return 0;
}
반응형