Problem | 1953 | User | finchpark |
Memory | 260K | Time | 16MS |
Language | C++ | Result | Accepted |
#include <iostream> using namespace std; int trumpet(int num); int main() { int getLineNum = 0; int getPatternNum = 0; int *scenario; cin >> getLineNum; scenario = (int*)malloc(sizeof(int) * getLineNum); for(int i = 0; i < getLineNum; i++) { cin >> getPatternNum; scenario[i] = getPatternNum; } cout << endl; for(int i = 0; i < getLineNum; i++) cout << "Scenario #" << i + 1 << ":" << endl << trumpet(scenario[i]) << endl << endl; free(scenario); return 0; } int trumpet(int num) { int temp = 0; int result_1 = 2; int result_2 = 3; if(num == 1) return result_1; else if(num == 2) return result_2; else{ for(int i = 2; i < num; i++) { temp = result_1 + result_2; result_1 = result_2; result_2 = temp; } return result_2; } }
#include <iostream> using namespace std; int trumpet(int num); int main() { int getLineNum = 0; int getPatternNum = 0; int *scenario; cin >> getLineNum; scenario = (int*)malloc(sizeof(int) * getLineNum); for(int i = 0; i < getLineNum; i++) { cin >> getPatternNum; scenario[i] = getPatternNum; cout << "Scenario #" << i + 1 << ":" << endl << trumpet(scenario[i]) << endl << endl; } free(scenario); return 0; } int trumpet(int num) { int temp = 0; int result_1 = 2; int result_2 = 3; if(num == 1) return result_1; else if(num == 2) return result_2; else{ for(int i = 2; i < num; i++) { temp = result_1 + result_2; result_1 = result_2; result_2 = temp; } return result_2; } }