From 5aff1adbd0d53866f7692c1d212a33f3e212d717 Mon Sep 17 00:00:00 2001 From: Ishan Ahmad Date: Wed, 11 Oct 2023 21:46:06 +0600 Subject: [PATCH] added new folder for UVA problem solutions with 8 solutions which i have solved myself --- ONLINE JUDGE/UVA/Age_Sort.cpp | 39 +++++++++ ONLINE JUDGE/UVA/Andys_First_Dictionary.cpp | 65 +++++++++++++++ ONLINE JUDGE/UVA/Horror_Dash.cpp | 38 +++++++++ .../UVA/Slogan_Learning_of_Princess.cpp | 29 +++++++ ONLINE JUDGE/UVA/The_3n+1_problem.cpp | 55 +++++++++++++ ...he_Department_of_Redundancy_Department.cpp | 37 +++++++++ ONLINE JUDGE/UVA/The_Playboy_Chimp.cpp | 81 +++++++++++++++++++ ONLINE JUDGE/UVA/What_is_the_Median.cpp | 27 +++++++ 8 files changed, 371 insertions(+) create mode 100644 ONLINE JUDGE/UVA/Age_Sort.cpp create mode 100644 ONLINE JUDGE/UVA/Andys_First_Dictionary.cpp create mode 100644 ONLINE JUDGE/UVA/Horror_Dash.cpp create mode 100644 ONLINE JUDGE/UVA/Slogan_Learning_of_Princess.cpp create mode 100644 ONLINE JUDGE/UVA/The_3n+1_problem.cpp create mode 100644 ONLINE JUDGE/UVA/The_Department_of_Redundancy_Department.cpp create mode 100644 ONLINE JUDGE/UVA/The_Playboy_Chimp.cpp create mode 100644 ONLINE JUDGE/UVA/What_is_the_Median.cpp diff --git a/ONLINE JUDGE/UVA/Age_Sort.cpp b/ONLINE JUDGE/UVA/Age_Sort.cpp new file mode 100644 index 0000000..de28c0d --- /dev/null +++ b/ONLINE JUDGE/UVA/Age_Sort.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std; + +int main() +{ + vector v; + int n, a; + + + while(cin >> n) + { + if(n == 0) + { + break; + } + while(n--) + { + cin >> a; + v.push_back(a); + } + sort(v.begin(), v.end()); + int sv = v.size(); + + for(int i = 0; i < sv; i++) + { + cout << v[i]; + if(i < sv-1) + { + cout << " "; + } + } + cout << endl; + v.clear(); + } + + return 0; +} diff --git a/ONLINE JUDGE/UVA/Andys_First_Dictionary.cpp b/ONLINE JUDGE/UVA/Andys_First_Dictionary.cpp new file mode 100644 index 0000000..d5e0f3e --- /dev/null +++ b/ONLINE JUDGE/UVA/Andys_First_Dictionary.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +using namespace std; + + +int main() +{ + set st; + vector V; + string s, s2; + + + while(cin >> s) + { + int sizeof_string = s.size(); + + for(int i = 0; i < sizeof_string; i++) + { + if(s[i] >= 65 && s[i] <= 90) + { + s2 += (s[i] + 32); + } + else if(s[i] >= 97 && s[i] <= 122) + { + s2 += s[i]; + } + else + { + + if(s2.size() != 0) + { + //cout << s2.size() << endl; + V.push_back(s2); + s2.clear(); + } + } + } + if(s2.size() != 0) + { + //cout << s2.size() << endl; + V.push_back(s2); + s2.clear(); + } + } + + + sort(V.begin(), V.end()); + int sizeof_vector = V.size(); + for(int i = 0; i < sizeof_vector; i++) + { + st.insert(V[i]); + } + + set ::iterator it; + + for(it = st.begin(); it != st.end(); it++) + { + cout << *it << endl; + } + + return 0; +} diff --git a/ONLINE JUDGE/UVA/Horror_Dash.cpp b/ONLINE JUDGE/UVA/Horror_Dash.cpp new file mode 100644 index 0000000..522432b --- /dev/null +++ b/ONLINE JUDGE/UVA/Horror_Dash.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +using namespace std; + +void solve(); + +int main() +{ + + solve(); + + return 0; +} + +void solve() +{ + int t, cs = 1, mx, n, m; + + cin >> t; + + while(t--) + { + mx = 0; + cin >> n; + while(n--) + { + cin >> m; + if(mx < m) + { + mx = m; + } + } + cout << "Case " << cs++ << ": " << mx << endl; + } +} + diff --git a/ONLINE JUDGE/UVA/Slogan_Learning_of_Princess.cpp b/ONLINE JUDGE/UVA/Slogan_Learning_of_Princess.cpp new file mode 100644 index 0000000..1bc0b8e --- /dev/null +++ b/ONLINE JUDGE/UVA/Slogan_Learning_of_Princess.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +using namespace std; + +int main() +{ + map mp; + string s1, s2, s3; + int n, m; + + cin >> n; + cin.ignore(); + while(n--) + { + getline(cin, s1); + getline(cin, s2); + mp.insert(make_pair(s1, s2)); + } + cin >> m; + cin.ignore(); + while(m--) + { + getline(cin, s1); + cout << mp[s1] << endl; + } + return 0; +} diff --git a/ONLINE JUDGE/UVA/The_3n+1_problem.cpp b/ONLINE JUDGE/UVA/The_3n+1_problem.cpp new file mode 100644 index 0000000..2b1d295 --- /dev/null +++ b/ONLINE JUDGE/UVA/The_3n+1_problem.cpp @@ -0,0 +1,55 @@ +#include + +using namespace std; +typedef long long ll; +ll mx = 0; + +void fn(ll n); +int main() +{ + ll i, j, tmp; + + while(cin >> i >> j) + { + cout << i << " " << j; + if(j < i) + { + tmp = i; + i = j; + j = tmp; + } + for(ll k = i; k <= j; k++) + { + fn(k); + } + cout << " " << mx << endl; + mx = 0; + } + + return 0; +} +void fn(ll n) +{ + ll c = 0; + while(n != 1) + { + c++; + if(n == 1) + { + break; + } + if(n%2 == 0) + { + n /= 2; + } + else + { + n = n*3 + 1; + } + } + c++; + if(c >= mx) + { + mx = c; + } +} \ No newline at end of file diff --git a/ONLINE JUDGE/UVA/The_Department_of_Redundancy_Department.cpp b/ONLINE JUDGE/UVA/The_Department_of_Redundancy_Department.cpp new file mode 100644 index 0000000..33ec23e --- /dev/null +++ b/ONLINE JUDGE/UVA/The_Department_of_Redundancy_Department.cpp @@ -0,0 +1,37 @@ +#include +#include +using namespace std; + +int main() +{ + vector v; + vector :: iterator it; + int i = 0, n, m, ss, c = 0; + + //getting input + while(cin >> n) + { + v.push_back(n); + } + ss = v.size(); + //input done + + while(v.size() > 0) + { + m = v[0]; + cout << m << " "; + for(it = v.begin(); it != v.end(); it++) + { + if(m == *it) + { + c++; + v.erase(it); + it--; + } + } + cout << c << endl; + c = 0; + } + + return 0; +} diff --git a/ONLINE JUDGE/UVA/The_Playboy_Chimp.cpp b/ONLINE JUDGE/UVA/The_Playboy_Chimp.cpp new file mode 100644 index 0000000..2890a03 --- /dev/null +++ b/ONLINE JUDGE/UVA/The_Playboy_Chimp.cpp @@ -0,0 +1,81 @@ +#include +#include +#include + +using namespace std; + +void solve1(); + +int main() +{ + + solve1(); + + return 0; +} +void solve1() +{ + long long t, n, q; + long long ara[100008]; + + cin >> t; + for(long long i = 0; i < t; i++) + { + cin >> ara[i]; + } + + cin >> q; + while(q--) + { + cin >> n; + + //cout << n << endl; + int f1 = 0, f2 = 0, f = 0; + for(int i = 0; i < t; i++) + { + //cout << ara[i] << endl; + if(n <= ara[i]) + { + f = 1; + for(int j = i; j >= 0; j--) + { + if(n > ara[j]) + { + cout << ara[j]; + f1 = 1; + break; + } + } + if(f1 == 0) + { + cout << "X "; + } + else + { + cout << " "; + } + + for(int j = i; j < t; j++) + { + if(n < ara[j]) + { + cout << ara[j]; + f2 = 1; + break; + } + } + if(f2 == 0) + { + cout << "X"; + } + } + if(f == 1) + { + cout << endl; + + break; + } + } + + } +} \ No newline at end of file diff --git a/ONLINE JUDGE/UVA/What_is_the_Median.cpp b/ONLINE JUDGE/UVA/What_is_the_Median.cpp new file mode 100644 index 0000000..9aef3e7 --- /dev/null +++ b/ONLINE JUDGE/UVA/What_is_the_Median.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +using namespace std; + +int main() +{ + vector v; + int N, i = 1, n; + + while(cin >> N) + { + v.push_back(N); + sort(v.begin(), v.end()); + if(i%2 != 0) + { + n = i/2; + cout << v[n] << endl; + } + else + { + cout << (v[n]+v[n+1])/2 << endl; + } + i++; + } + return 0; +}