Skip to content

solutions for UVA problems #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ONLINE JUDGE/UVA/Age_Sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector <int> 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;
}
65 changes: 65 additions & 0 deletions ONLINE JUDGE/UVA/Andys_First_Dictionary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;


int main()
{
set <string> st;
vector <string> 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 <string>::iterator it;

for(it = st.begin(); it != st.end(); it++)
{
cout << *it << endl;
}

return 0;
}
38 changes: 38 additions & 0 deletions ONLINE JUDGE/UVA/Horror_Dash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <cmath>
#include <algorithm>

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;
}
}

29 changes: 29 additions & 0 deletions ONLINE JUDGE/UVA/Slogan_Learning_of_Princess.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main()
{
map <string, string> 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;
}
55 changes: 55 additions & 0 deletions ONLINE JUDGE/UVA/The_3n+1_problem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>

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;
}
}
37 changes: 37 additions & 0 deletions ONLINE JUDGE/UVA/The_Department_of_Redundancy_Department.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>
using namespace std;

int main()
{
vector <int> v;
vector <int> :: 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;
}
81 changes: 81 additions & 0 deletions ONLINE JUDGE/UVA/The_Playboy_Chimp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <iostream>
#include <cmath>
#include <algorithm>

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;
}
}

}
}
27 changes: 27 additions & 0 deletions ONLINE JUDGE/UVA/What_is_the_Median.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector <long long> 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;
}