mirror of
https://github.com/tiennm99/codechef.git
synced 2026-06-13 12:10:33 +00:00
[Add] solved solutions
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n,
|
||||
a,
|
||||
e = 0,
|
||||
o = 0;
|
||||
cin >> n;
|
||||
while (n--) {
|
||||
cin >> a;
|
||||
if (a%2 == 0)
|
||||
++e;
|
||||
else
|
||||
++o;
|
||||
}
|
||||
if (e > o)
|
||||
cout << "READY FOR BATTLE";
|
||||
else
|
||||
cout << "NOT READY";
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
switch (n%8)
|
||||
{
|
||||
case 0:
|
||||
cout << n - 1 << "SL";
|
||||
break;
|
||||
case 1:
|
||||
cout << n + 3 << "LB";
|
||||
break;
|
||||
case 2:
|
||||
cout << n + 3 << "MB";
|
||||
break;
|
||||
case 3:
|
||||
cout << n + 3 << "UB";
|
||||
break;
|
||||
case 4:
|
||||
cout << n - 3 << "LB";
|
||||
break;
|
||||
case 5:
|
||||
cout << n - 3 << "MB";
|
||||
break;
|
||||
case 6:
|
||||
cout << n - 3 << "UB";
|
||||
break;
|
||||
case 7:
|
||||
cout << n + 1 << "SU";
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void xu_ly(int n)
|
||||
{
|
||||
bool mang[n + 1] = {0}, t, i;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> t;
|
||||
mang[t] = 1;
|
||||
}
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
if (!mang[i])
|
||||
{
|
||||
cout << i << " ";
|
||||
}
|
||||
}
|
||||
//cout << '\b';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
xu_ly(n);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
int count = 0;
|
||||
int l = s.length();
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
if (s[i] == '<' && s[i + 1] == '>')
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int t;
|
||||
long long a, b;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> a >> b;
|
||||
if (a < b)
|
||||
cout << "<";
|
||||
else if (a > b)
|
||||
cout << ">";
|
||||
else
|
||||
cout << "=";
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char ch;
|
||||
int c, h, e, f;
|
||||
c = h = e = f = 0;
|
||||
do
|
||||
{
|
||||
ch = getchar();
|
||||
if (ch == 'C')
|
||||
{
|
||||
c++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ch == 'H' && c > h)
|
||||
{
|
||||
h++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ch == 'E' && h > e)
|
||||
{
|
||||
e++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ch == 'F' && e > f)
|
||||
{
|
||||
f++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (ch != '\n');
|
||||
cout << f << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, i, p, a, b;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> p;
|
||||
b = 0;
|
||||
a = 2048;
|
||||
while (a)
|
||||
{
|
||||
b = b + p/a;
|
||||
p = p%a;
|
||||
a = a/2;
|
||||
}
|
||||
cout << b << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
} toa_do;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
double khoang_cach;
|
||||
toa_do chef, head_server, sous_chef;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> khoang_cach;
|
||||
cin >> chef.x >> chef.y;
|
||||
cin >> head_server.x >> head_server.y;
|
||||
cin >> sous_chef.x >> sous_chef.y;
|
||||
if (sqrt(pow(sous_chef.x - chef.x, 2) + pow(sous_chef.y - chef.y, 2)) <= khoang_cach ||
|
||||
(sqrt(pow(sous_chef.x - head_server.x, 2) + pow(sous_chef.y - head_server.y, 2)) <= khoang_cach &&
|
||||
sqrt(pow(head_server.x - chef.x, 2) + pow(head_server.y - chef.y, 2)) <= khoang_cach))
|
||||
{
|
||||
cout << "yes" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "no" << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool kiem_tra(int n)
|
||||
{
|
||||
string s[50];
|
||||
int i;
|
||||
bool b = 1;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> s[i];
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (s[i] == "cookie" && (i == (n - 1) || s[i + 1] == "cookie"))
|
||||
{
|
||||
b = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> n;
|
||||
if (kiem_tra(n))
|
||||
{
|
||||
cout << "YES" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int t;
|
||||
int d;
|
||||
} internet;
|
||||
|
||||
int main()
|
||||
{
|
||||
int tc, i, sum, n, k;
|
||||
internet inter[10];
|
||||
cin >> tc;
|
||||
while (tc--)
|
||||
{
|
||||
sum = 0;
|
||||
cin >> n >> k;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> inter[i].t >> inter[i].d;
|
||||
}
|
||||
i = 0;
|
||||
while (k > 0 || i == n)
|
||||
{
|
||||
if (k > inter[i].t)
|
||||
{
|
||||
k -= inter[i].t;
|
||||
inter[i].t = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
inter[i].t -= k;
|
||||
k = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
sum += inter[i].t*inter[i].d;
|
||||
}
|
||||
cout << sum << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
|
||||
#define MAX 1000
|
||||
|
||||
using namespace std;
|
||||
|
||||
void factorial(int n)
|
||||
{
|
||||
int *a = new int[MAX];
|
||||
int size = 0;
|
||||
int t = n;
|
||||
while (t != 0)
|
||||
{
|
||||
a[size] = t%10;
|
||||
t /= 10;
|
||||
size++;
|
||||
}
|
||||
for (int x = 2; x < n; x++)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
a[i] *= x;
|
||||
}
|
||||
for (int i = 0; i < size - 1; i++)
|
||||
{
|
||||
a[i + 1] += a[i]/10;
|
||||
a[i] %= 10;
|
||||
}
|
||||
while (a[size - 1] >= 10)
|
||||
{
|
||||
a[size] = a[size - 1]/10;
|
||||
a[size - 1] %= 10;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
for (int i = size - 1; i >= 0; i--)
|
||||
{
|
||||
cout << a[i];
|
||||
}
|
||||
cout << endl;
|
||||
delete[] a;
|
||||
a = NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
factorial(n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, a, b, i;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> a >> b;
|
||||
cout << a%b << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n, i, fdigit, ldigit;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> n;
|
||||
ldigit = n%10;
|
||||
while (n)
|
||||
{
|
||||
fdigit = n%10;
|
||||
n = n/10;
|
||||
}
|
||||
cout << fdigit + ldigit << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n, i, j, sum, a[6] = {1, 2, 5, 10, 50, 100};
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> n;
|
||||
sum = 0;
|
||||
for (j = 5; j >= 0; j--)
|
||||
{
|
||||
sum += n/a[j];
|
||||
n = n%a[j];
|
||||
}
|
||||
cout << sum << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n, i, sum;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> n;
|
||||
sum = 0;
|
||||
while (n)
|
||||
{
|
||||
sum = sum + n%10;
|
||||
n = n/10;
|
||||
}
|
||||
cout << sum << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n, i, s;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
s = 0;
|
||||
cin >> n;
|
||||
while (n)
|
||||
{
|
||||
s = s*10 + n%10;
|
||||
n = n/10;
|
||||
}
|
||||
cout << s << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, i;
|
||||
double q, p, sum;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> q >> p;
|
||||
sum = q*p;
|
||||
if (q > 1000)
|
||||
{
|
||||
sum = sum*9/10;
|
||||
}
|
||||
cout << fixed << sum << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, i;
|
||||
char c;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> c;
|
||||
switch (c)
|
||||
{
|
||||
case 'b':
|
||||
case 'B':
|
||||
cout << "BattleShip" << endl;
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
cout << "Cruiser" << endl;
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
cout << "Destroyer" << endl;
|
||||
break;
|
||||
case 'f':
|
||||
case 'F':
|
||||
cout << "Frigate" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, i;
|
||||
double tlcb, tl, hra, da;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> tlcb;
|
||||
if (tlcb < 1500)
|
||||
{
|
||||
hra = 0.1*tlcb;
|
||||
da = 0.9*tlcb;
|
||||
}
|
||||
else
|
||||
{
|
||||
hra = 500;
|
||||
da = 0.98*tlcb;
|
||||
}
|
||||
tl = tlcb + hra + da;
|
||||
cout << fixed << tl << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, a, b, c, i;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> a >> b >> c;
|
||||
if (a + b + c == 180 && a > 0 && b > 0 && c > 0)
|
||||
{
|
||||
cout << "YES" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, g;
|
||||
float h, cc, ts;
|
||||
bool i, ii, iii;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> h >> cc >> ts;
|
||||
if (h > 50)
|
||||
{
|
||||
i = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
if (cc < 0.7)
|
||||
{
|
||||
ii = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ii = 0;
|
||||
}
|
||||
if (ts > 5600)
|
||||
{
|
||||
iii = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
iii = 0;
|
||||
}
|
||||
if (i && ii && iii)
|
||||
{
|
||||
g = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i && ii)
|
||||
{
|
||||
g = 9;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ii && iii)
|
||||
{
|
||||
g = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i && iii)
|
||||
{
|
||||
g = 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i || ii || iii)
|
||||
{
|
||||
g = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
g = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << g << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum days
|
||||
{
|
||||
SUNDAY,
|
||||
MONDAY,
|
||||
TUESDAY,
|
||||
WEDNESDAY,
|
||||
THURSDAY,
|
||||
FRIDAY,
|
||||
SATURDAY
|
||||
};
|
||||
|
||||
char* day[7] =
|
||||
{
|
||||
"sunday",
|
||||
"monday",
|
||||
"tuesday",
|
||||
"wednesday",
|
||||
"thursday",
|
||||
"friday",
|
||||
"saturday",
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, nam, index;
|
||||
cin >> t;
|
||||
for (index = 0; index < t; index++)
|
||||
{
|
||||
cin >> nam;
|
||||
int gt_nam, gt_thang, gia_tri, tong_gia_tri;
|
||||
bool kt_nam_nhuan;
|
||||
gt_nam = nam/100;
|
||||
if ((nam%4 == 0 && nam%100 != 0) || (nam%400 ==0))
|
||||
{
|
||||
kt_nam_nhuan = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
kt_nam_nhuan = 0;
|
||||
}
|
||||
gt_nam = gt_nam%4;
|
||||
switch (gt_nam)
|
||||
{
|
||||
case 3:
|
||||
gt_nam = 0;
|
||||
break;
|
||||
case 2:
|
||||
gt_nam = 2;
|
||||
break;
|
||||
case 1:
|
||||
gt_nam = 4;
|
||||
break;
|
||||
case 0:
|
||||
gt_nam = 6;
|
||||
break;
|
||||
}
|
||||
if (kt_nam_nhuan)
|
||||
{
|
||||
gt_thang = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
gt_thang = 0;
|
||||
}
|
||||
tong_gia_tri = nam%100;
|
||||
gia_tri = tong_gia_tri/4;
|
||||
tong_gia_tri = tong_gia_tri + gia_tri + gt_nam + gt_thang + 1;
|
||||
tong_gia_tri = tong_gia_tri%7;
|
||||
cout << day[tong_gia_tri] << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
unsigned long long int gcd(int a, int b) {
|
||||
unsigned long long int temp;
|
||||
while (b != 0)
|
||||
{
|
||||
temp = a % b;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned long long int t, a, b, l, g;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> a >> b;
|
||||
g = gcd(a, b);
|
||||
l = a*b/g;
|
||||
cout << g << " " << l << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int max2(int a, int b, int c)
|
||||
{
|
||||
if (a > b)
|
||||
{
|
||||
if (b > c)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c > a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (a > c)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (b > c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int t, a, b, c;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> a >> b >> c;
|
||||
cout << max2(a, b, c) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
unsigned long long int fact(int n)
|
||||
{
|
||||
unsigned long long int x = 1;
|
||||
int i;
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
x *= i;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> n;
|
||||
cout << fact(n) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
long long n, k, m;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
cin >> n >> k;
|
||||
m = 0;
|
||||
for (long long i = 1; i <= k; ++i)
|
||||
if (n % i > m)
|
||||
m = n % i;
|
||||
cout << m << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int x;
|
||||
float y;
|
||||
cin >> x >> y;
|
||||
if (x%5 == 0 && (y - x) > 0.5)
|
||||
{
|
||||
cout << y - (x + 0.5) << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << y << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
unsigned long n, k, i, count = 0;
|
||||
unsigned long long a;
|
||||
cin >> n >> k;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a;
|
||||
if (a%k == 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, i, n, sum;
|
||||
cin >> t;
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> n;
|
||||
sum = 0;
|
||||
while (n)
|
||||
{
|
||||
if (n%10 == 4)
|
||||
{
|
||||
sum++;
|
||||
}
|
||||
n = n/10;
|
||||
}
|
||||
cout << sum << endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, t, i;
|
||||
cin >> n;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> t;
|
||||
cout << t/2 + 1 << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, l1, l2 = 0, l3 = 0, i, j;
|
||||
char s1[400], s2[400], s3[400];
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> s1;
|
||||
l1 = strlen(s1);
|
||||
for (i = 0; i < l1; i++)
|
||||
{
|
||||
if (isalpha(s1[i]))
|
||||
{
|
||||
s3[l3++] = s1[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
s2[l2++] = s1[i];
|
||||
if (s1[i] == ')')
|
||||
{
|
||||
for (j = l2 - 1; s2[j] != '('; j--)
|
||||
{
|
||||
if (s2[j] != ')')
|
||||
{
|
||||
s3[l3++] = s2[j];
|
||||
}
|
||||
}
|
||||
l2 = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < l3; i++)
|
||||
{
|
||||
cout << s3[i];
|
||||
}
|
||||
cout << endl;
|
||||
l2 = 0;
|
||||
l3 = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool check(int n)
|
||||
{
|
||||
int a[5];
|
||||
int size = 0;
|
||||
int t = n;
|
||||
while (t != 0)
|
||||
{
|
||||
a[size] = t%10;
|
||||
t /= 10;
|
||||
size++;
|
||||
}
|
||||
for (int i = 0; i < size/2; i++)
|
||||
{
|
||||
if (a[i] != a[size - 1 - i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
if (check(n))
|
||||
{
|
||||
cout << "wins" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "losses" << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool check(int n)
|
||||
{
|
||||
int a[n], i;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (a[a[i] - 1] != i + 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
do
|
||||
{
|
||||
cin >> n;
|
||||
if (n)
|
||||
{
|
||||
if (check(n))
|
||||
{
|
||||
cout << "ambiguous" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "not ambiguous" << endl;
|
||||
}
|
||||
}
|
||||
} while (n);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
|
||||
#define MAX_SIZE 100000
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
bool prime[MAX_SIZE];
|
||||
prime[0] = prime[1] = 0;
|
||||
for (int i = 2; i < MAX_SIZE; i++)
|
||||
{
|
||||
prime[i] = 1;
|
||||
}
|
||||
for (int i = 0; i < MAX_SIZE; i++)
|
||||
{
|
||||
if (prime[i])
|
||||
{
|
||||
for (int j = 2*i; j < MAX_SIZE; j += i)
|
||||
{
|
||||
prime[j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
if (prime[n])
|
||||
{
|
||||
cout << "yes" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "no" << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void process(int n);
|
||||
int gcd(int x, int y);
|
||||
|
||||
void process(int n)
|
||||
{
|
||||
int i, g, a[n];
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
g = gcd(a[0], a[1]);
|
||||
for (i = 2; i < n; i++)
|
||||
{
|
||||
g = gcd(g, a[i]);
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
a[i] /= g;
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
int gcd(int x, int y)
|
||||
{
|
||||
if (y > x)
|
||||
{
|
||||
return gcd(y, x);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x%y == 0)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return gcd(y, x%y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> n;
|
||||
process(n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, a, b;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> a >> b;
|
||||
cout << (a > b ? a : b) << " " << a + b << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
#include <climits>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
long long t, n, min1, min2, temp;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
cin >> n;
|
||||
min1 = INT_MAX;
|
||||
min2 = INT_MAX;
|
||||
for (long long i = 0; i < n; ++i) {
|
||||
cin >> temp;
|
||||
if (temp < min1) {
|
||||
min2 = min1;
|
||||
min1 = temp;
|
||||
} else if (temp < min2) {
|
||||
min2 = temp;
|
||||
}
|
||||
}
|
||||
cout << min1 + min2 << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, i, l = 0, w = 0, a, b, c = 0, d = 0;
|
||||
cin >> n;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a >> b;
|
||||
c = c + a;
|
||||
d = d + b;
|
||||
if (abs(c - d) > l)
|
||||
{
|
||||
l = abs(c - d);
|
||||
if (c > d)
|
||||
{
|
||||
w = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << w << " " << l << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
unsigned short t;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
unsigned short n;
|
||||
cin >> n;
|
||||
unsigned short **a = new unsigned short*[n];
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
a[i] = new unsigned short[n];
|
||||
}
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
for (unsigned short j = 0; j < n; j++)
|
||||
{
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
int max = 0;
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
max += a[i][i];
|
||||
}
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
int t = 0;
|
||||
for (unsigned short j = 0; j < n - i; j++)
|
||||
{
|
||||
t += a[0 + j][i + j];
|
||||
}
|
||||
if (t > max)
|
||||
{
|
||||
max = t;
|
||||
}
|
||||
}
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
int t = 0;
|
||||
for (unsigned short j = 0; j < n - i; j++)
|
||||
{
|
||||
t += a[i + j][0 + j];
|
||||
}
|
||||
if (t > max)
|
||||
{
|
||||
max = t;
|
||||
}
|
||||
}
|
||||
/*
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
for (unsigned short j = 0; j < n; j++)
|
||||
{
|
||||
if (i != 0 && j != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
for (unsigned short k = 1; k <= n - ((i > j)?i:j); k++)
|
||||
{
|
||||
int temp = 0;
|
||||
for (unsigned short l = 0; l < k; l++)
|
||||
{
|
||||
temp += a[i + l][j + l];
|
||||
}
|
||||
if (temp > max)
|
||||
{
|
||||
max = temp;
|
||||
}
|
||||
cout << temp << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
cout << max << endl;
|
||||
delete[] a;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void quickSort(unsigned int arr[], unsigned int left, unsigned int right) {
|
||||
|
||||
int i = left, j = right;
|
||||
|
||||
int tmp;
|
||||
|
||||
int pivot = arr[(left + right) / 2];
|
||||
|
||||
|
||||
|
||||
/* partition */
|
||||
|
||||
while (i <= j) {
|
||||
|
||||
while (arr[i] < pivot)
|
||||
|
||||
i++;
|
||||
|
||||
while (arr[j] > pivot)
|
||||
|
||||
j--;
|
||||
|
||||
if (i <= j) {
|
||||
|
||||
tmp = arr[i];
|
||||
|
||||
arr[i] = arr[j];
|
||||
|
||||
arr[j] = tmp;
|
||||
|
||||
i++;
|
||||
|
||||
j--;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* recursion */
|
||||
|
||||
if (left < j)
|
||||
|
||||
quickSort(arr, left, j);
|
||||
|
||||
if (i < right)
|
||||
|
||||
quickSort(arr, i, right);
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned int t, i;
|
||||
cin >> t;
|
||||
unsigned int a[t];
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
quickSort(a, 0, t);
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
cout << a[i] << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char s[100];
|
||||
int t, i, l, dem_0, dem_1;
|
||||
cin >> t;
|
||||
while (t--)
|
||||
{
|
||||
cin >> s;
|
||||
dem_0 = dem_1 = i = 0;
|
||||
l = strlen(s);
|
||||
for (i = 0; i < l; i++)
|
||||
{
|
||||
if (s[i] == '0')
|
||||
{
|
||||
dem_0++;
|
||||
}
|
||||
}
|
||||
dem_1 = l - dem_0;
|
||||
if (dem_1 > dem_0)
|
||||
{
|
||||
cout << "WIN" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "LOSE" << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, n, c;
|
||||
long long *a, m;
|
||||
string c1, c2;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
c = 0;
|
||||
m = 0;
|
||||
cin >> n;
|
||||
cin >> c1 >> c2;
|
||||
a = new long long[n + 1];
|
||||
for (int i = 0; i <= n; ++i)
|
||||
cin >> a[i];
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (c1[i] == c2[i])
|
||||
++c;
|
||||
}
|
||||
if (c == n) {
|
||||
cout << a[n] << endl;
|
||||
} else {
|
||||
for (int i = 0; i <= c; ++i) {
|
||||
if (a[i] > m)
|
||||
m = a[i];
|
||||
}
|
||||
cout << m << endl;
|
||||
}
|
||||
|
||||
delete [] a;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user