Skip to content

Commit

Permalink
Merge pull request #101 from shreenanda-8/master
Browse files Browse the repository at this point in the history
Updated ladder B
  • Loading branch information
kothariji authored Oct 3, 2020
2 parents 0d2fe88 + d09d244 commit b249b45
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 0 deletions.
47 changes: 47 additions & 0 deletions A2OJ/B/015.Find Marble.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<bits/stdc++.h>


#define ll long long
#define max 1000000000




using namespace std;


int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);

ll n, s, t;
cin >> n >> s >> t;
ll arr[n];
arr[0] = -1;
for (ll i = 1; i <= n; i++)
{
cin >> arr[i];
}
ll index, value, ans = -1, cnt = 0;
index = s;
value = arr[index];
while (cnt < n)
{
if (value == index && t != index)
{
ans = -1;
break;
}
else if (t == index)
{
ans = cnt;
break;
}
index = value;
value = arr[index];
cnt++;
}
cout << ans;
return 0;
}
91 changes: 91 additions & 0 deletions A2OJ/B/020.Little Girl and Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include<bits/stdc++.h>


#define ll long long



using namespace std;
int main()
{
string s;
cin >> s;
ll H[26] = {0};
for (ll i = 0; i < s.length(); i++)
{
H[s[i] - 'a']++;
}
ll even = 0, odd = 0;
for (ll i = 0; i < 26; i++)
{
if (H[i] % 2 == 0)
{
even++;
}
else
{
odd++;
}
}
ll cn = 0;
if (odd <= 1)
{
cout << "First" << "\n";

}
else
{
if (even % 2 == 0)
{
for (ll i = 0; i < 26; i++)
{
if (H[i] % 2 == 0)
{
H[i]--;
}
}
for (ll i = 0; i < 26; i++)
{
if (H[i] % 2 != 0)
{
cn++;
}
}
if (cn % 2 != 0)
{
cout << "First" << "\n";
}
else
{
cout << "Second" << "\n";
}
}
else
{
for (ll i = 0; i < 26; i++)
{
if (H[i] % 2 == 0)
{
H[i]--;
}
}
for (ll i = 0; i < 26; i++)
{
if (H[i] % 2 != 0)
{
cn++;
}
}
if (cn % 2 != 0)
{
cout << "Second" << "\n";
}
else
{
cout << "First" << "\n";
}
}
}

return 0;
}
42 changes: 42 additions & 0 deletions A2OJ/B/022.Books.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<bits/stdc++.h>


#define ll long long
#define mm 1000000001

using namespace std;

//They are everywhere
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll n, t;
cin >> n >> t;
ll arr[n];
for (ll i = 0; i < n; i++)
{
cin >>arr[i];
}
ll start = 0, sum = 0, cnt = 0;
vector<ll>ans;
for (ll i = 0; i < n; i++)
{
sum += arr[i];
if (sum <= t)
{
cnt++;
}
else
{
sum -= arr[start];
ans.push_back(cnt);
cnt = i - start;
start++;

}
}
ans.push_back(cnt);
cout << *max_element(ans.begin(), ans.end());
return 0;
}
65 changes: 65 additions & 0 deletions A2OJ/B/025.Vasya and Wrestling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
set<ll> usinversal;
ll ans = 0;
ll aa = 0;


int main()
{
fast;

ll n;
cin >> n;
ll sum1 = 0, sum2= 0;
vector<ll> a1, a2;
bool l;
while (n--)
{
ll x;
cin >>x;
if (x >= 0)
{
sum1 += x;
a1.push_back(x);
l = true;
}
else
{
sum2 += -1 *x;
a2.push_back(-1 * x);
l = false;
}
}

if (sum1 >sum2)
{
cout << "first" << "\n";
}
else if (sum2 > sum1)
{
cout << "second" << "\n";
}
else
{
if (a1 > a2)
{
cout << "first" << "\n";
}
else if (a1 < a2)
{
cout <<"second" << "\n";
}
else if (l)
{
cout << "first" << "\n";
}
else
{
cout << "second" << "\n";
}
}
return 0;
}

0 comments on commit b249b45

Please sign in to comment.