Created
December 10, 2025 16:39
-
-
Save XoLinA/c55402be6a9b0bd9fcdafa3b4bbb3bb5 to your computer and use it in GitHub Desktop.
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 <vector> | |
| using namespace std; | |
| int Sum(const vector<int>& a) | |
| { | |
| int sum = 0; | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| int x = a[i]; | |
| if (x < 0) | |
| { | |
| x = -x; | |
| } | |
| while (x > 0) | |
| { | |
| sum += x % 10; | |
| x /= 10; | |
| } | |
| } | |
| return sum; | |
| } | |
| double AVGplus(const vector<int>& a) | |
| { | |
| int sum = 0; | |
| int temp = 0; | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| if (a[i] > 0) | |
| { | |
| sum += a[i]; | |
| temp++; | |
| } | |
| } | |
| return sum / temp; | |
| } | |
| void ShowMin(const vector<int>& a) | |
| { | |
| int temp = a[0]; | |
| int ind = 0; | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| if (a[i] < temp) | |
| { | |
| temp = a[i]; | |
| ind = i; | |
| } | |
| } | |
| cout << "Min: " << temp << " Index: " << ind << endl; | |
| } | |
| int Best(const vector<int>& a) | |
| { | |
| int best = a[0], bestTemp = 0; | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| int temp = 0; | |
| for (int j = 0; j < a.size(); j++) | |
| { | |
| if (a[j] == a[i]) temp++; | |
| } | |
| if (temp > bestTemp) | |
| { | |
| bestTemp = temp; | |
| best = a[i]; | |
| } | |
| } | |
| return best; | |
| } | |
| int Odd(const vector<int>& a) | |
| { | |
| int temp = a[0]; | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| if (i % 2 == 0) | |
| { | |
| if (a[i] % 3 == 0) | |
| { | |
| if (temp < a[i]) | |
| { | |
| temp = a[i]; | |
| } | |
| } | |
| } | |
| } | |
| return temp; | |
| } | |
| void Change(vector<int>& a) | |
| { | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| cout << a[i] << " "; | |
| } | |
| cout << endl; | |
| int maxE = -1000000, minO = 1000000; | |
| int posE = -1, posO = -1; | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| if (a[i] % 2 == 0 && a[i] > maxE) | |
| { | |
| maxE = a[i]; | |
| posE = i; | |
| } | |
| if (a[i] % 2 != 0 && a[i] < minO) | |
| { | |
| minO = a[i]; | |
| posO = i; | |
| } | |
| } | |
| if (posE != -1 && posO != -1) | |
| { | |
| swap(a[posE], a[posO]); | |
| } | |
| else for (int i = 0; i < a.size(); i++) | |
| { | |
| a[i] = 0; | |
| } | |
| for (int i = 0; i < a.size(); i++) | |
| { | |
| cout << a[i] << " "; | |
| } | |
| } | |
| void UnionInter(const vector<int>& a, const vector<int>& b) | |
| { | |
| int n = a.size(); | |
| int m = b.size(); | |
| int both[100], onlyOne[100]; | |
| int bC = 0, oC = 0; | |
| for (int i = 0; i < n; i++) | |
| { | |
| bool found = false; | |
| for (int j = 0; j < m; j++) | |
| { | |
| if (a[i] == b[j]) | |
| { | |
| found = true; | |
| break; | |
| } | |
| } | |
| if (found) | |
| both[bC++] = a[i]; | |
| else | |
| onlyOne[oC++] = a[i]; | |
| } | |
| for (int j = 0; j < m; j++) | |
| { | |
| bool found = false; | |
| for (int i = 0; i < n; i++) | |
| { | |
| if (b[j] == a[i]) | |
| { | |
| found = true; | |
| break; | |
| } | |
| } | |
| if (!found) | |
| { | |
| onlyOne[oC++] = b[j]; | |
| } | |
| } | |
| cout << "\na) Both array: "; | |
| for (int i = 0; i < bC; i++) | |
| { | |
| cout << both[i] << " "; | |
| } | |
| cout << "\nb) Only in 1 array: "; | |
| for (int i = 0; i < oC; i++) | |
| { | |
| cout << onlyOne[i] << " "; | |
| } | |
| cout << endl; | |
| } | |
| int main() | |
| { | |
| vector<int>a{ 10,23,-23,-4,90,10 }; | |
| vector<int>b{ 1,23,-3,50,-4,10 }; | |
| cout << "Sum: " << Sum(a) << endl; | |
| cout << "AVGplus: " << AVGplus(a) << endl; | |
| ShowMin(a); | |
| cout << "Best: " << Best(a) << endl; | |
| cout << "Max/3: " << Odd(a); | |
| cout << endl<<"Change min_max: "<<endl; | |
| Change(a); | |
| UnionInter(a, b); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment