View Code of Problem 80

#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	while (cin >> n && n != 0) {
		vector <int> data;
		data.push_back(1);
		data.push_back(2);
		data.push_back(2);
		data.push_back(1);
		data.push_back(4);
		for (int i = 5; i < n; i++)
		{
			if (data[i - 1] + 3 > i + 1) {
				data.push_back(data[i - 1] + 3 - i - 1);
			}
			else {
				data.push_back(data[i - 1] + 3);
			}
		}
		cout << data[n - 1] << endl;
	}
}

Double click to view unformatted code.


Back to problem 80