Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- #define INPUT "..\\tess.txt"
- #define OUTPUT "output.txt"
- /**
- * реалізував числа Фібоначчі. якщо сума попередніх 2 == число то вилучають його
- * Перші 2 числа вилучаємо
- *
- * Маємо -> 1 2 3 12 4 16
- * вилучаємо 1 и 2. Третій елемент 3 то вилучаємо так як перший + другий елемент == 3
- * Шостий величаемо так як 12+ 4 == 16
- * Відповідь маємо ряд: 12 4
- * @return 0
- */
- int main() {
- // creat array numbers
- vector<int> list_number;
- // open file in read mode
- fstream file(INPUT, ios::in | ios::binary);
- string number;
- // read all numbers with numbers.txt
- while (getline(file, number, ' ')) {
- list_number.push_back(stoi(number));
- }
- file.close();
- // open file in write mode
- file.open(OUTPUT, ios::out);
- // write numbers to a file that are not Fibonacci numbers
- if (list_number.size() > 2) {
- for (int i = 2; i < int(list_number.size()); i++) {
- if (list_number[i - 2] + list_number[i - 1] != list_number[i]) {
- file << list_number[i] << ' ';
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment