Skip to content

Commit 141395b

Browse files
Added SPOJ problems
1 parent beb2ec1 commit 141395b

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

SPOJ/Arranging Amplifiers.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* SPOJ */
2+
/* Title - Arranging Amplifiers */
3+
/* Created By - Kushagra Saxena */
4+
/* Date - 04/10/2020 */
5+
6+
//Problem link - https://www.spoj.com/problems/ARRANGE/
7+
8+
9+
#include<bits/stdc++.h>
10+
using namespace std;
11+
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define rep(i,a,b) for(ll i=a; i<b; i++)
13+
#define per(i,a,b) for(ll i=a; i>=b; i--)
14+
#define ll long long int
15+
#define ld long double
16+
#define vi vector<ll>
17+
#define vii vector <pair<ll,ll> >
18+
#define pb push_back
19+
#define mkp make_pair
20+
#define ff first
21+
#define ss second
22+
#define MOD 1000000007
23+
#define umap unordered_map<ll, ll>
24+
#define map map<ll, ll>
25+
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
26+
#define mems(a, i) memset(a, i, sizeof(a))
27+
#define endl '\n'
28+
#define all(v) v.begin(),v.end()
29+
#define gcd(a,b) __gcd((a),(b))
30+
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
31+
#define deba(a) cout << #a << " " << a << endl;
32+
int main()
33+
{
34+
fast;
35+
int t;
36+
cin >> t;
37+
while (t--)
38+
{
39+
ll n;
40+
cin >> n;
41+
vi a1, a2, a3;
42+
rep(i, 0, n)
43+
{
44+
ll x;
45+
cin >> x;
46+
if (x == 1)
47+
a1.pb(1);
48+
else if (x == 2 or x == 3)
49+
a2.pb(x);
50+
else
51+
a3.pb(x);
52+
}
53+
vi ans;
54+
if (a1.size() > 0)
55+
{
56+
rep(i, 0, a1.size())
57+
ans.pb(a1[i]);
58+
}
59+
ll fl = 0;
60+
if (a3.size() > 0)
61+
{
62+
fl = 1;
63+
sort(all(a3), greater<>());
64+
rep(i, 0, a3.size())
65+
ans.pb(a3[i]);
66+
}
67+
if (a2.size() > 0)
68+
{
69+
if (fl == 1)
70+
sort(all(a2), greater<>());
71+
else
72+
sort(all(a2));
73+
rep(i, 0, a2.size())
74+
ans.pb(a2[i]);
75+
}
76+
rep(i, 0, ans.size())
77+
cout << ans[i] << " ";
78+
cout << endl;
79+
}
80+
return 0;
81+
}

SPOJ/The last digit.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* SPOJ */
2+
/* Title - Arranging Amplifiers */
3+
/* Created By - Kushagra Saxena */
4+
/* Date - 04/10/2020 */
5+
6+
//Problem link - https://www.spoj.com/problems/LASTDIG/
7+
8+
9+
// Nestor was doing the work of his math class about three days but he is tired of make operations a lot and he
10+
// should deliver his task tomorrow. His math’s teacher gives him two numbers a and b. The problem consist of finding
11+
// the last digit of the potency of base a and index b. Help Nestor with his problem. You are given two integer numbers:
12+
// the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0.
13+
// You have to find the last digit of ab.
14+
15+
// Input
16+
// The first line of input contains an integer t, the number of test cases (t <= 30). t test cases follow.
17+
// For each test case will appear a and b separated by space.
18+
19+
// Output
20+
// For each test case output an integer per line representing the result
21+
22+
// Sample Input
23+
// Input:
24+
// 2
25+
// 3 10
26+
// 6 2
27+
28+
// Output:
29+
// 9
30+
// 6
31+
32+
33+
#include<bits/stdc++.h>
34+
using namespace std;
35+
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
36+
#define ll long long int
37+
ll modularExpo(ll a, ll n, ll MOD)
38+
{
39+
ll res = 1;
40+
while (n > 0)
41+
{
42+
if (n % 2 == 0)
43+
a = (a * a) % MOD, n /= 2;
44+
else
45+
res = (res * a) % MOD , n--;
46+
}
47+
return res;
48+
}
49+
int main()
50+
{
51+
fast;
52+
int t;
53+
scanf("%d", &t);
54+
while (t--)
55+
{
56+
ll a, b;
57+
scanf("%lld%lld", &a, &b);
58+
printf("%lld\n", modularExpo(a, b, 10));
59+
}
60+
return 0;
61+
}

0 commit comments

Comments
 (0)