Created
March 23, 2020 13:48
-
-
Save matisiekpl/0a57d51d8135e891b560895aa52d29c2 to your computer and use it in GitHub Desktop.
IT school assignment for idiots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <fstream> | |
| #include <string> | |
| #include <math.h> | |
| #include <limits> | |
| using namespace std; | |
| int octal_to_decimal(int octal) { | |
| int decimal_number = 0, i = 0, rem; | |
| while (octal != 0) { | |
| rem = octal % 10; | |
| octal /= 10; | |
| decimal_number += rem * pow(8, i); | |
| ++i; | |
| } | |
| return decimal_number; | |
| } | |
| int main() { | |
| ofstream result; | |
| result.open("C:\\Users\\Mateusz\\CLionProjects\\infa1\\wyniki6.txt"); | |
| int n = 5000; | |
| ifstream file; | |
| file.open("C:\\Users\\Mateusz\\CLionProjects\\infa1\\dane.txt"); | |
| string numbers[n]; | |
| for (int i = 0; i < n; i++) getline(file, numbers[i]); | |
| // Task A | |
| int count = 0; | |
| for (int i = 0; i < n; i++) if (numbers[i].front() == numbers[i].back()) count++; | |
| result << "A" << endl; | |
| result << count << endl; | |
| // Task B | |
| result << "B" << endl; | |
| for (int i = 0; i < n; i++) | |
| if (to_string(octal_to_decimal(stoi(numbers[i]))).front() == | |
| to_string(octal_to_decimal(stoi(numbers[i]))).back()) | |
| result << numbers[i] << endl; | |
| // Task C | |
| result << "C" << endl; | |
| int accepted_count = 0; | |
| int min_accepted = INT_MAX; | |
| int max_accepted = 0; | |
| for (int i = 0; i < n; i++) { | |
| bool accepted = true; | |
| char previous = numbers[i][0]; | |
| for (int a = 1; a < numbers[i].length(); a++) { | |
| if (numbers[i][a] < previous) accepted = false; | |
| previous = numbers[i][a]; | |
| } | |
| if (accepted) { | |
| accepted_count++; | |
| int number = stoi(numbers[i]); | |
| if (number > max_accepted) max_accepted = number; | |
| if (number < min_accepted) min_accepted = number; | |
| } | |
| } | |
| result << accepted_count << endl; | |
| result << max_accepted << endl; | |
| result << min_accepted << endl; | |
| // Finish | |
| result.close(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment