mirror of
https://github.com/tiennm99/codeforces.git
synced 2026-06-09 14:11:38 +00:00
[Init] Solved solutions
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
int sum = 0;
|
||||
for (string::iterator i = s.begin(); i != s.end(); i++)
|
||||
{
|
||||
if (*i == '4' || *i == '7')
|
||||
{
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
if (sum == 4 || sum == 7)
|
||||
{
|
||||
cout << "YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void low(string &s)
|
||||
{
|
||||
for (unsigned int i = 0; i < s.length(); i++)
|
||||
{
|
||||
if (isupper(s[i]))
|
||||
{
|
||||
s[i] = tolower(s[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int compare(string s1, string s2)
|
||||
{
|
||||
int l;
|
||||
if (s1.length() > s2.length())
|
||||
{
|
||||
l = s2.length();
|
||||
}
|
||||
else
|
||||
{
|
||||
l = s1.length();
|
||||
}
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
if (s1[i] > s2[i])
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (s1[i] < s2[i])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (s1.length() > s2.length())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (s1.length() < s2.length())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
string s1, s2;
|
||||
getline(cin, s1);
|
||||
getline(cin, s2);
|
||||
low(s1);
|
||||
low(s2);
|
||||
cout << compare(s1, s2) << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char c[6] = {'a', 'o', 'y', 'e', 'u', 'i'};
|
||||
string s;
|
||||
cin >> s;
|
||||
for (unsigned int i = 0; i < s.length(); i++)
|
||||
{
|
||||
if (isupper(s[i]) == 1)
|
||||
{
|
||||
s[i] = tolower(s[i]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
while (s.find(c[i]) != -1)
|
||||
{
|
||||
int pos = s.find(c[i]);
|
||||
s.replace(pos, 1, "");
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < s.length(); i += 2)
|
||||
{
|
||||
s.insert(i, ".");
|
||||
}
|
||||
cout << s << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned short i;
|
||||
cin >> i;
|
||||
if (i%4 && i%7 && i%44 && i%47 && i%77 && i%74 && i%444 && i%447 && i%477 && i%777 && i%774 && i%744 && i%474 && i%747) {
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "YES" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char c[] = "HQ9";
|
||||
string s;
|
||||
cin >> s;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (s.find(c[i]) != -1) {
|
||||
cout << "YES" << endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
cout << "NO" << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int *a = new int[n];
|
||||
int *b = new int[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
b[a[i] - 1] = i + 1;
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cout << b[i] << " ";
|
||||
}
|
||||
delete[] a;
|
||||
a = NULL;
|
||||
delete[] b;
|
||||
b = NULL;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, o,
|
||||
imax = 0,
|
||||
imin = 0;
|
||||
cin >> n;
|
||||
int *a = new int[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
if (a[i] > a[imax])
|
||||
{
|
||||
imax = i;
|
||||
}
|
||||
if (a[i] <= a[imin])
|
||||
{
|
||||
imin = i;
|
||||
}
|
||||
}
|
||||
o = n - 1 - imin + imax;
|
||||
if (imax > imin)
|
||||
{
|
||||
o--;
|
||||
}
|
||||
cout << o;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int k, l, m, n, d, count = 0;
|
||||
cin >> k >> l >> m >> n >> d;
|
||||
for (int i = 1; i <= d; i++)
|
||||
{
|
||||
if ((i%k == 0) || (i%l == 0) || (i%m == 0) || (i%n == 0))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
cout << count;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int k, n, count = 0;
|
||||
cin >> k >> n;
|
||||
int arr[k];
|
||||
for (int i = 0; i < k; i++)
|
||||
{
|
||||
cin >> arr[i];
|
||||
}
|
||||
for (int i = 0; i < k; i++)
|
||||
{
|
||||
if (arr[i] > 0 && arr[i] >= arr[n - 1])
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int a[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
a[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
switch (t)
|
||||
{
|
||||
case 1:
|
||||
a[0]++;
|
||||
break;
|
||||
case 2:
|
||||
a[1]++;
|
||||
break;
|
||||
case 3:
|
||||
a[2]++;
|
||||
break;
|
||||
case 4:
|
||||
a[3]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int count = 0;
|
||||
int s = 0;
|
||||
count += a[3];
|
||||
count += a[2];
|
||||
if (a[0] >= a[2])
|
||||
{
|
||||
a[0] -= a[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
a[0] = 0;
|
||||
}
|
||||
count += a[1]/2;
|
||||
a[1] %= 2;
|
||||
s += a[1]*2 + a[0];
|
||||
if (s%4)
|
||||
{
|
||||
count += (s/4 + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
count += s/4;
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int *a = new int[n];
|
||||
int sum = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> a[i];
|
||||
sum += a[i];
|
||||
}
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (a[i] < a[j]) {
|
||||
int t = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
int s = 0, x = 0;
|
||||
while (s <= sum) {
|
||||
s += a[x];
|
||||
sum -= a[x];
|
||||
x++;
|
||||
}
|
||||
cout << x << endl;
|
||||
delete[] a;
|
||||
return 0;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned long long n, m, a;
|
||||
cin >> n >> m >> a;
|
||||
cout << ((n%a) ? (n/a + 1) : (n/a))*((m%a) ? (m/a + 1) : (m/a)) << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
int *a;
|
||||
double *arr;
|
||||
cin >> n;
|
||||
a = new int[n];
|
||||
for (int i = 0; i < n; ++i)
|
||||
a[i] = 1;
|
||||
arr = new double[n];
|
||||
for (int i = 0; i < n; ++i)
|
||||
cin >> arr[i];
|
||||
while (n > 1) {
|
||||
for (int i = 0; i < n / 2; ++i) {
|
||||
int sum = a[i] + a[n - i - 1];
|
||||
arr[i] = (double) a[i] / sum * arr[i] + (double) a[n - i - 1] / sum * arr[n - i - 1];
|
||||
a[i] = sum;
|
||||
}
|
||||
n = (n + 1) / 2;
|
||||
}
|
||||
cout << setprecision(6) << arr[0] << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned int a, b, c, d;
|
||||
cin >> a >> b >> c >> d;
|
||||
unsigned count = 0;
|
||||
if (a == b || a == c || a == d)
|
||||
count++;
|
||||
if (b == c || b == d)
|
||||
count++;
|
||||
if (c == d)
|
||||
count++;
|
||||
cout << count;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
unsigned int i = 0;
|
||||
while (i < s.length()) {
|
||||
unsigned int index = s.find_last_of(s[i]);
|
||||
while (index != i) {
|
||||
s.replace(index, 1, "");
|
||||
index = s.find_last_of(s[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (s.length()%2) {
|
||||
cout << "IGNORE HIM!";
|
||||
}
|
||||
else {
|
||||
cout << "CHAT WITH HER!";
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int i1, i2, c1 = 0, c2 = 0;
|
||||
while (n--)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
if (t%2)
|
||||
{
|
||||
c1++;
|
||||
i1 = c1 + c2;
|
||||
}
|
||||
else
|
||||
{
|
||||
c2++;
|
||||
i2 = c1 + c2;
|
||||
}
|
||||
}
|
||||
if (c1 < c2)
|
||||
{
|
||||
cout << i1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << i2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
if (t == 1)
|
||||
{
|
||||
cout << abs(i - 2) + abs(j - 2) << endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
char *ptr = new char[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin >> ptr[i];
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
if (ptr[i] == ptr[i - 1])
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
delete[] ptr;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, t;
|
||||
cin >> n >> t;
|
||||
string s;
|
||||
cin >> s;
|
||||
while (t--)
|
||||
{
|
||||
for (string::iterator i = s.begin(); i != s.end(); i++)
|
||||
{
|
||||
if (*i == 'B' && *(i + 1) == 'G')
|
||||
{
|
||||
*i = 'G';
|
||||
*(i + 1) = 'B';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << s;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, c = 0;
|
||||
cin >> n;
|
||||
int *a = new int[n];
|
||||
int *b = new int[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i] >> b[i];
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
if (a[i] == b[j])
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << c;
|
||||
delete[] a;
|
||||
a = NULL;
|
||||
delete[] b;
|
||||
b = NULL;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool check(int n)
|
||||
{
|
||||
int a = n/1000;
|
||||
int b = (n/100)%10;
|
||||
if (b == a)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int c = (n/10)%10;
|
||||
if (c == a || c == b)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int d = n%10;
|
||||
if (d == a || d == b || d == c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
do
|
||||
{
|
||||
n++;
|
||||
} while (check(n) == 0);
|
||||
cout << n;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
if (islower(s[0]))
|
||||
{
|
||||
s[0] = toupper(s[0]);
|
||||
}
|
||||
cout << s << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, x = 0;
|
||||
cin >> n;
|
||||
while (n--)
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
if (s.find("++") != -1)
|
||||
{
|
||||
x++;
|
||||
}
|
||||
if (s.find("--") != -1)
|
||||
{
|
||||
x--;
|
||||
}
|
||||
}
|
||||
cout << x << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
unsigned long long int out(unsigned long long int n, unsigned long long int k)
|
||||
{
|
||||
if (k <= n/2)
|
||||
{
|
||||
return 2*k - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (k - n/2)*2;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned long long int n, k;
|
||||
cin >> n >> k;
|
||||
if (n%2)
|
||||
{
|
||||
cout << out(n + 1, k);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << out(n, k);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
int *a = new int[m];
|
||||
for (int i = 0; i < m; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
for (int i = 0; i < m - 1; i++)
|
||||
{
|
||||
for (int j = i + 1; j < m; j++)
|
||||
{
|
||||
if (a[j] < a[i])
|
||||
{
|
||||
int t = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
int delta = a[n - 1] - a[0];
|
||||
for (int i = 1; i <= m - n; i++)
|
||||
{
|
||||
int temp = a[i + n - 1] - a[i];
|
||||
if (temp < delta)
|
||||
{
|
||||
delta = temp;
|
||||
}
|
||||
}
|
||||
cout << delta;
|
||||
delete[] a;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#define MAX_SIZE 100
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
stringstream ss;
|
||||
getline(cin, s);
|
||||
ss.str(s);
|
||||
int arr[MAX_SIZE];
|
||||
char c;
|
||||
int n = 0;
|
||||
while(!ss.eof())
|
||||
{
|
||||
ss >> arr[n++] >> c;
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = i + 1; j < n; j++)
|
||||
{
|
||||
if (arr[j] < arr[i])
|
||||
{
|
||||
int temp = arr[i];
|
||||
arr[i] = arr[j];
|
||||
arr[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cout << arr[i];
|
||||
if (i != n - 1)
|
||||
{
|
||||
cout << '+';
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, m, now = 1;
|
||||
unsigned long long int c = 0;
|
||||
cin >> n >> m;
|
||||
for (int i = 0; i < m; i++)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
if (t < now)
|
||||
{
|
||||
c = c + t + n - now;
|
||||
}
|
||||
else
|
||||
{
|
||||
c = c + t - now;
|
||||
}
|
||||
now = t;
|
||||
}
|
||||
cout << c;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int count = 1;
|
||||
int a;
|
||||
cin >> a;
|
||||
while (--n)
|
||||
{
|
||||
int b;
|
||||
cin >> b;
|
||||
if (b != a)
|
||||
{
|
||||
count++;
|
||||
a = b;
|
||||
}
|
||||
}
|
||||
cout << count;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b, d = 0, c = 0;
|
||||
cin >> a >> b;
|
||||
do
|
||||
{
|
||||
while (a > 0)
|
||||
{
|
||||
c += a;
|
||||
d += a%b;
|
||||
a /= b;
|
||||
}
|
||||
a = d/b;
|
||||
d %= b;
|
||||
}
|
||||
while (a > 0);
|
||||
cout << c;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int *a = new int[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
for (int i = 0; i < n - 1; i++)
|
||||
{
|
||||
for (int j = i + 1; j < n; j++)
|
||||
{
|
||||
if (a[i] > a[j])
|
||||
{
|
||||
int temp = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
delete[] a;
|
||||
return 0;
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool check(string s, string t)
|
||||
{
|
||||
if (s.length() != t.length())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
{
|
||||
if (s[i] != t[t.length() - 1 -i])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
string s, t;
|
||||
cin >> s >> t;
|
||||
if (check(s, t))
|
||||
{
|
||||
cout << "YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
int c = 0;
|
||||
getline(cin, s);
|
||||
for (int i = s.length() - 2; i > 0; i -= 3)
|
||||
{
|
||||
if (s.find(s[i]) == i)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
cout << c;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
if (a > b)
|
||||
{
|
||||
a = b;
|
||||
}
|
||||
if (a%2)
|
||||
{
|
||||
cout << "Akshat";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Malvika";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int sum = 0;
|
||||
while (n--)
|
||||
{
|
||||
int p, q;
|
||||
cin >> p >> q;
|
||||
if (q - p >= 2)
|
||||
{
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
cout << sum;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void input(bool *a, int n, int x)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
a[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
int t1;
|
||||
cin >> t1;
|
||||
for (int j = 0; j < t1; j++)
|
||||
{
|
||||
int t2;
|
||||
cin >> t2;
|
||||
a[t2 - 1] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool check(bool *a, int x)
|
||||
{
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
if (a[i] == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
bool *a = new bool[n];
|
||||
input (a, n, 2);
|
||||
if (check(a, n))
|
||||
{
|
||||
cout << "I become the guy.";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Oh, my keyboard!";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
bool *b = new bool[n];
|
||||
b[0] = b[1] = 0;
|
||||
for (int i = 2; i < n; i++)
|
||||
{
|
||||
b[i] = 1;
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (b[i] == 1)
|
||||
{
|
||||
for (int j = 2*i; j < n; j += i)
|
||||
{
|
||||
b[j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 2; i < n; i++)
|
||||
{
|
||||
if (b[i] == 0 && b[n - i] == 0)
|
||||
{
|
||||
cout << i << " " << n - i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete[] b;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
int arr[6];
|
||||
arr[0] = a + b + c;
|
||||
arr[1] = a*b*c;
|
||||
arr[2] = a+b*c;
|
||||
arr[3] = a*b+c;
|
||||
arr[4] = (a + b)*c;
|
||||
arr[5] = a*(b + c);
|
||||
int max = arr[0];
|
||||
for (int i = 1; i < 6; i++)
|
||||
{
|
||||
if (arr[i] > max)
|
||||
{
|
||||
max = arr[i];
|
||||
}
|
||||
}
|
||||
cout << max;
|
||||
return 0;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
if (n%2 || n <= 2)
|
||||
{
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "YES" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, t;
|
||||
cin >> n >> t;
|
||||
int *a = new int[n - 1];
|
||||
for (int i = 0; i < n - 1; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
int pos = 0;
|
||||
while (pos < t - 1)
|
||||
{
|
||||
pos += a[pos];
|
||||
}
|
||||
if (pos == t - 1)
|
||||
{
|
||||
cout << "YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO";
|
||||
}
|
||||
delete[] a;
|
||||
a = NULL;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
for (int i = 0; i < n ; i++)
|
||||
{
|
||||
switch (i%4)
|
||||
{
|
||||
case 1:
|
||||
for (int i = 0; i < m - 1; i++)
|
||||
{
|
||||
cout << ".";
|
||||
}
|
||||
cout << "#" << endl;
|
||||
break;
|
||||
case 3:
|
||||
cout << "#";
|
||||
for (int i = 0; i < m - 1; i++)
|
||||
{
|
||||
cout << ".";
|
||||
}
|
||||
cout << endl;
|
||||
break;
|
||||
default:
|
||||
for (int i = 0; i < m; i++)
|
||||
{
|
||||
cout << "#";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool check(string s)
|
||||
{
|
||||
for (string::iterator it = s.begin(); it != s.end(); it++)
|
||||
{
|
||||
*it = toupper(*it);
|
||||
}
|
||||
for (unsigned char c = 'A'; c <= 'Z'; c++)
|
||||
{
|
||||
if (s.find(c) == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned short n;
|
||||
string s;
|
||||
cin >> n >> s;
|
||||
if (check(s))
|
||||
{
|
||||
cout << "YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool check(string s)
|
||||
{
|
||||
string c = "hello";
|
||||
for (unsigned int i = 0; i < c.length(); i++)
|
||||
{
|
||||
int pos = s.find(c[i]);
|
||||
if (pos != -1)
|
||||
{
|
||||
s.replace(0, pos + 1, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
getline(cin, s);
|
||||
if (check(s))
|
||||
{
|
||||
cout << "YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO";
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
int up = 0, low = 0;
|
||||
for (string::iterator it = s.begin(); it!= s.end(); it++)
|
||||
{
|
||||
if (islower(*it))
|
||||
{
|
||||
low++;
|
||||
}
|
||||
else if (isupper(*it))
|
||||
{
|
||||
up++;
|
||||
}
|
||||
}
|
||||
if (up > low)
|
||||
{
|
||||
for (string::iterator it = s.begin(); it != s.end(); it++)
|
||||
{
|
||||
*it = toupper(*it);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (string::iterator it = s.begin(); it != s.end(); it++)
|
||||
{
|
||||
*it = tolower(*it);
|
||||
}
|
||||
}
|
||||
cout << s;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
long long int *a, *b;
|
||||
cin >> n >> m;
|
||||
a = new long long int[n];
|
||||
b = new long long int[m];
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> a[i];
|
||||
for (int i = 0; i < m; i++)
|
||||
cin >> b[i];
|
||||
sort(a, a + n);
|
||||
for (int i = 0; i < m; i++)
|
||||
cout << upper_bound(a, a + n, b[i]) - a << " ";
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned long long int n;
|
||||
cin >> n;
|
||||
if (n%5 == 0)
|
||||
{
|
||||
cout << n/5;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << (n/5 + 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s1, s2;
|
||||
cin >> s1 >> s2;
|
||||
for (unsigned int i = 0; i < s1.length(); i++)
|
||||
{
|
||||
if (s1[i] == s2[i])
|
||||
{
|
||||
cout << 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, h, l = 0;
|
||||
cin >> n >> h;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
if (t > h)
|
||||
{
|
||||
l++;
|
||||
}
|
||||
}
|
||||
cout << l + n;
|
||||
return 0;
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, x, y, z;
|
||||
cin >> n;
|
||||
x = y = z = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
x += t;
|
||||
cin >> t;
|
||||
y += t;
|
||||
cin >> t;
|
||||
z += t;
|
||||
}
|
||||
if (x == 0 && y == 0 && z == 0)
|
||||
{
|
||||
cout << "YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
while (n--)
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
if (s.length() > 10)
|
||||
{
|
||||
cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << s << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned int ca, cd, n;
|
||||
string s;
|
||||
cin >> n;
|
||||
ca = 0;
|
||||
cd = 0;
|
||||
cin >> s;
|
||||
for (string::iterator it = s.begin(); it != s.end(); it++)
|
||||
{
|
||||
if (*it == 'A')
|
||||
{
|
||||
ca++;
|
||||
}
|
||||
else if (*it == 'D')
|
||||
{
|
||||
cd++;
|
||||
}
|
||||
}
|
||||
if (ca > cd)
|
||||
{
|
||||
cout << "Anton";
|
||||
}
|
||||
else if (ca < cd)
|
||||
{
|
||||
cout << "Danik";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Friendship";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int size = 5;
|
||||
char* c[size] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};
|
||||
int n, m = 0, r = 1;
|
||||
cin >> n;
|
||||
while (n > m)
|
||||
{
|
||||
m += size*r;
|
||||
r *= 2;
|
||||
}
|
||||
r /= 2;
|
||||
n = n - m + size*r;
|
||||
int pos = n/r;
|
||||
if (n%r == 0)
|
||||
{
|
||||
pos--;
|
||||
}
|
||||
cout << c[pos];
|
||||
return 0;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
if (s.find("0000000") != -1 || s.find("1111111") != -1)
|
||||
{
|
||||
cout << "YES" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool arr[200000];
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned int n, c = 0;
|
||||
cin >> n;
|
||||
while (n--)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
if (t < 0)
|
||||
{
|
||||
t += 200001;
|
||||
}
|
||||
if (arr[t - 1] == 0 && t != 0)
|
||||
{
|
||||
c++;
|
||||
arr[t - 1] = 1;
|
||||
}
|
||||
}
|
||||
cout << c;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool b[10];
|
||||
|
||||
int main()
|
||||
{
|
||||
unsigned short n, m;
|
||||
cin >> n >> m;
|
||||
int *a = new int[n];
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
for (unsigned short i = 0; i < m; i++)
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
b[t] = 1;
|
||||
}
|
||||
for (unsigned short i = 0; i < n; i++)
|
||||
{
|
||||
if (b[a[i]] == 1)
|
||||
{
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
}
|
||||
delete[] a;
|
||||
a = NULL;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user