Initial commit
This commit is contained in:
53
2022/sector/code/code.cpp
Normal file
53
2022/sector/code/code.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
ifstream input_stream;
|
||||
ofstream output_stream;
|
||||
|
||||
|
||||
uint16_t generateNumber(uint16_t first, uint16_t second, uint16_t third, uint16_t fourth) {
|
||||
return first * 1000 + second * 100 + third * 10 + fourth;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
input_stream.open("input.txt");
|
||||
output_stream.open("output.txt");
|
||||
|
||||
uint16_t first, third;
|
||||
// File method:
|
||||
// input_stream >> first;
|
||||
// input_stream >> third;
|
||||
// Console method:
|
||||
cin >> first;
|
||||
cin >> third;
|
||||
|
||||
uint16_t total = 0;
|
||||
|
||||
for (uint16_t second = 0; second <= 9; second++) {
|
||||
for (uint16_t fourth = 0; fourth <= 9; fourth++) {
|
||||
uint16_t generatedNumber = generateNumber(first, second, third, fourth);
|
||||
if (generatedNumber % 9 == 0) {
|
||||
// File method:
|
||||
// output_stream << generatedNumber << endl;
|
||||
// Console method:
|
||||
cout << generatedNumber << endl;
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// File method:
|
||||
// output_stream << total << endl;
|
||||
// Console method:
|
||||
cout << total << endl;
|
||||
|
||||
input_stream.close();
|
||||
output_stream.close();
|
||||
return 0;
|
||||
}
|
||||
73
2022/sector/insule/insule.cpp
Normal file
73
2022/sector/insule/insule.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
ifstream input_stream;
|
||||
ofstream output_stream;
|
||||
|
||||
|
||||
void runMarkdown(bool mx[][100], bool mk[][100], uint16_t nodeX, uint16_t nodeY, uint8_t N) {
|
||||
mk[nodeY][nodeX] = true;
|
||||
|
||||
// Top
|
||||
if (nodeY - 1 >= 0 && mx[nodeY - 1][nodeX] && !mk[nodeY - 1][nodeX]) {
|
||||
runMarkdown(mx, mk, nodeX, nodeY - 1, N);
|
||||
}
|
||||
|
||||
// Bottom
|
||||
if (nodeY + 1 < N && mx[nodeY + 1][nodeX] && !mk[nodeY + 1][nodeX]) {
|
||||
runMarkdown(mx, mk, nodeX, nodeY + 1, N);
|
||||
}
|
||||
|
||||
// Left
|
||||
if (nodeX - 1 >= 0 && mx[nodeY][nodeX - 1] && !mk[nodeY][nodeX - 1]) {
|
||||
runMarkdown(mx, mk, nodeX - 1, nodeY, N);
|
||||
}
|
||||
|
||||
// Right
|
||||
if (nodeX + 1 < N && mx[nodeY][nodeX + 1] && !mk[nodeY][nodeX + 1]) {
|
||||
runMarkdown(mx, mk, nodeX + 1, nodeY, N);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
input_stream.open("Insule.txt");
|
||||
output_stream.open("output.txt");
|
||||
|
||||
uint16_t N;
|
||||
input_stream >> N;
|
||||
|
||||
bool matrix[N][100];
|
||||
bool marks[N][100];
|
||||
|
||||
for (uint8_t i = 0; i < N; i++) {
|
||||
for (uint8_t j = 0; j < N; j++) {
|
||||
input_stream >> matrix[i][j];
|
||||
marks[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t total = 0;
|
||||
|
||||
for (uint16_t i = 0; i < N; i++) {
|
||||
for (uint16_t j = 0; j < N; j++) {
|
||||
if (matrix[i][j] && !marks[i][j]) {
|
||||
runMarkdown(matrix, marks, j, i, N);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// File method:
|
||||
// output_stream << total << endl;
|
||||
// Console method:
|
||||
cout << total << endl;
|
||||
|
||||
input_stream.close();
|
||||
return 0;
|
||||
}
|
||||
7
2022/sector/insule/tests/insule1.txt
Normal file
7
2022/sector/insule/tests/insule1.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
6
|
||||
0 1 0 1 1 0
|
||||
1 1 0 0 1 1
|
||||
0 0 0 0 0 1
|
||||
1 0 1 0 0 0
|
||||
1 1 1 1 0 0
|
||||
0 0 0 0 1 1
|
||||
10
2022/sector/insule/tests/insule10.txt
Normal file
10
2022/sector/insule/tests/insule10.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
4
|
||||
1 1 1 1
|
||||
1 1 0 0
|
||||
0 0 1 1
|
||||
1 0 1 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4
2022/sector/insule/tests/insule2.txt
Normal file
4
2022/sector/insule/tests/insule2.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
3
|
||||
1 0 1
|
||||
0 0 0
|
||||
1 0 1
|
||||
8
2022/sector/insule/tests/insule3.txt
Normal file
8
2022/sector/insule/tests/insule3.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
7
|
||||
0 0 0 0 0 0 0
|
||||
0 0 1 1 0 0 1
|
||||
1 1 1 0 0 1 1
|
||||
0 0 0 1 0 0 0
|
||||
1 0 0 1 0 0 0
|
||||
1 1 0 0 1 1 1
|
||||
0 1 0 0 1 0 0
|
||||
6
2022/sector/insule/tests/insule4.txt
Normal file
6
2022/sector/insule/tests/insule4.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
5
|
||||
0 0 1 0 0
|
||||
0 0 1 0 0
|
||||
1 1 1 1 1
|
||||
0 1 0 0 0
|
||||
0 1 0 0 0
|
||||
5
2022/sector/insule/tests/insule5.txt
Normal file
5
2022/sector/insule/tests/insule5.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
4
|
||||
1 1 1 1
|
||||
0 1 0 0
|
||||
0 0 0 1
|
||||
0 0 1 1
|
||||
8
2022/sector/insule/tests/insule6.txt
Normal file
8
2022/sector/insule/tests/insule6.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
6
|
||||
1 1 0 1 1 0
|
||||
1 1 0 0 1 1
|
||||
0 0 0 1 1 1
|
||||
1 0 1 0 0 0
|
||||
1 0 1 1 1 0
|
||||
1 1 1 0 1 1
|
||||
|
||||
6
2022/sector/insule/tests/insule7.txt
Normal file
6
2022/sector/insule/tests/insule7.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
3
|
||||
0 0 0
|
||||
0 0 0
|
||||
0 0 0
|
||||
|
||||
|
||||
11
2022/sector/insule/tests/insule8.txt
Normal file
11
2022/sector/insule/tests/insule8.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
7
|
||||
0 0 1 1 0 1 0
|
||||
0 0 1 1 0 1 1
|
||||
1 1 1 1 0 1 1
|
||||
0 1 0 1 0 0 0
|
||||
1 1 0 1 1 0 0
|
||||
1 1 0 0 1 1 1
|
||||
0 1 0 0 1 0 0
|
||||
|
||||
|
||||
|
||||
10
2022/sector/insule/tests/insule9.txt
Normal file
10
2022/sector/insule/tests/insule9.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
5
|
||||
0 0 1 0 1
|
||||
0 1 1 1 0
|
||||
1 1 0 1 1
|
||||
0 1 0 1 1
|
||||
0 1 1 1 1
|
||||
|
||||
|
||||
|
||||
|
||||
75
2022/sector/palindrome/palindrome.cpp
Normal file
75
2022/sector/palindrome/palindrome.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ifstream input_stream;
|
||||
ofstream output_stream;
|
||||
|
||||
|
||||
bool is_palindrome(string s) {
|
||||
uint8_t s_len = s.length();
|
||||
|
||||
for (uint8_t i = 0; i < (s_len / 2); i++) {
|
||||
if (s[i] != s[s_len - i - 1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
input_stream.open("input.txt");
|
||||
output_stream.open("output.txt");
|
||||
|
||||
string max_pal, tmp;
|
||||
string inp = "";
|
||||
|
||||
// File method:
|
||||
while (true) {
|
||||
input_stream >> tmp;
|
||||
if (tmp == "") {
|
||||
break;
|
||||
}
|
||||
inp += " " + tmp;
|
||||
tmp = "";
|
||||
}
|
||||
|
||||
uint8_t max_pal_len = 0;
|
||||
|
||||
uint8_t inp_len = inp.length();
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < (inp_len - 1); i++) {
|
||||
for (uint8_t j = inp_len - i; j >= 2; j--) {
|
||||
if (j > max_pal_len) {
|
||||
string sub = inp.substr(i, j);
|
||||
if (is_palindrome(sub)) {
|
||||
max_pal_len = j;
|
||||
max_pal = sub;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// File method:
|
||||
// if (max_pal_len == 0) {
|
||||
// output_stream << "Nu se contine" << endl;
|
||||
// } else {
|
||||
// output_stream << max_pal << endl;
|
||||
// }
|
||||
// Console method:
|
||||
if (max_pal_len == 0) {
|
||||
cout << "Nu se contine" << endl;
|
||||
} else {
|
||||
cout << max_pal << endl;
|
||||
}
|
||||
|
||||
input_stream.close();
|
||||
output_stream.close();
|
||||
return 0;
|
||||
}
|
||||
1
2022/sector/palindrome/tests/textin1.txt
Normal file
1
2022/sector/palindrome/tests/textin1.txt
Normal file
@@ -0,0 +1 @@
|
||||
apacojoc
|
||||
1
2022/sector/palindrome/tests/textin10.txt
Normal file
1
2022/sector/palindrome/tests/textin10.txt
Normal file
@@ -0,0 +1 @@
|
||||
iepurasulusarupe
|
||||
1
2022/sector/palindrome/tests/textin2.txt
Normal file
1
2022/sector/palindrome/tests/textin2.txt
Normal file
@@ -0,0 +1 @@
|
||||
initial
|
||||
1
2022/sector/palindrome/tests/textin3.txt
Normal file
1
2022/sector/palindrome/tests/textin3.txt
Normal file
@@ -0,0 +1 @@
|
||||
port
|
||||
1
2022/sector/palindrome/tests/textin4.txt
Normal file
1
2022/sector/palindrome/tests/textin4.txt
Normal file
@@ -0,0 +1 @@
|
||||
niciunuicinueste
|
||||
1
2022/sector/palindrome/tests/textin5.txt
Normal file
1
2022/sector/palindrome/tests/textin5.txt
Normal file
@@ -0,0 +1 @@
|
||||
caracteristici
|
||||
1
2022/sector/palindrome/tests/textin6.txt
Normal file
1
2022/sector/palindrome/tests/textin6.txt
Normal file
@@ -0,0 +1 @@
|
||||
101101
|
||||
1
2022/sector/palindrome/tests/textin7.txt
Normal file
1
2022/sector/palindrome/tests/textin7.txt
Normal file
@@ -0,0 +1 @@
|
||||
d
|
||||
1
2022/sector/palindrome/tests/textin8.txt
Normal file
1
2022/sector/palindrome/tests/textin8.txt
Normal file
@@ -0,0 +1 @@
|
||||
nimeni nu cunoaste totul
|
||||
1
2022/sector/palindrome/tests/textin9.txt
Normal file
1
2022/sector/palindrome/tests/textin9.txt
Normal file
@@ -0,0 +1 @@
|
||||
abcdefghgfedcabra
|
||||
Reference in New Issue
Block a user