mirror of
https://github.com/tiennm99/codeforces.git
synced 2026-06-09 04:18:52 +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;
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
|
||||
namespace problem_1000A
|
||||
{
|
||||
class problem_1000A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = new int[9];
|
||||
for (int i = 0; i<n; i++)
|
||||
{
|
||||
string s = Console.ReadLine();
|
||||
if (s == "M")
|
||||
{
|
||||
a[0]++;
|
||||
}
|
||||
else if (s == "S")
|
||||
{
|
||||
a[1]++;
|
||||
}
|
||||
else if (s == "XS")
|
||||
{
|
||||
a[2]++;
|
||||
}
|
||||
else if (s == "XXS")
|
||||
{
|
||||
a[3]++;
|
||||
}
|
||||
else if (s == "XXXS")
|
||||
{
|
||||
a[4]++;
|
||||
}
|
||||
else if (s == "L")
|
||||
{
|
||||
a[5]++;
|
||||
}
|
||||
else if (s == "XL")
|
||||
{
|
||||
a[6]++;
|
||||
}
|
||||
else if (s == "XXL")
|
||||
{
|
||||
a[7]++;
|
||||
}
|
||||
else if (s == "XXXL")
|
||||
{
|
||||
a[8]++;
|
||||
}
|
||||
}
|
||||
int c = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
string s = Console.ReadLine();
|
||||
if (s == "M" && a[0] > 0)
|
||||
{
|
||||
a[0]--;
|
||||
}
|
||||
else if (s == "S" && a[1] > 0)
|
||||
{
|
||||
a[1]--;
|
||||
}
|
||||
else if (s == "XS" && a[2] > 0)
|
||||
{
|
||||
a[2]--;
|
||||
}
|
||||
else if (s == "XXS" && a[3] > 0)
|
||||
{
|
||||
a[3]--;
|
||||
}
|
||||
else if (s == "XXXS" && a[4] > 0)
|
||||
{
|
||||
a[4]--;
|
||||
}
|
||||
else if (s == "L" && a[5] > 0)
|
||||
{
|
||||
a[5]--;
|
||||
}
|
||||
else if (s == "XL" && a[6] > 0)
|
||||
{
|
||||
a[6]--;
|
||||
}
|
||||
else if (s == "XXL" && a[7] > 0)
|
||||
{
|
||||
a[7]--;
|
||||
}
|
||||
else if (s == "XXXL" && a[8] > 0)
|
||||
{
|
||||
a[8]--;
|
||||
}
|
||||
else
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
Console.Write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace problem_1004A
|
||||
{
|
||||
public class problem_1004A
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int n = ip[0];
|
||||
int d = ip[1];
|
||||
ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int id = 1;
|
||||
int count = 2;
|
||||
while (id < n)
|
||||
{
|
||||
if (ip[id] - ip[id - 1] > 2*d)
|
||||
{
|
||||
count += 2;
|
||||
}
|
||||
else if (ip[id] - ip[id - 1] == 2*d)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
id++;
|
||||
}
|
||||
Console.Write("{0}", count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace problem_1004B
|
||||
{
|
||||
class problem_1004B
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine().Split(' ')[0]);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
Console.Write("1");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace problem_1005A
|
||||
{
|
||||
class problem_1005A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
ArrayList b = new ArrayList();
|
||||
for (int i = 0; i < n - 1; i++)
|
||||
{
|
||||
if (a[i + 1] == 1)
|
||||
{
|
||||
b.Add(a[i]);
|
||||
}
|
||||
}
|
||||
b.Add(a[n - 1]);
|
||||
Console.WriteLine(b.Count);
|
||||
foreach (var t in b)
|
||||
{
|
||||
Console.Write("{0} ", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace problem_1006A
|
||||
{
|
||||
class problem_1006A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (a[i] % 2 == 0)
|
||||
{
|
||||
a[i]--;
|
||||
}
|
||||
}
|
||||
foreach (int t in a)
|
||||
{
|
||||
Console.Write("{0} ", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace problem_1006B
|
||||
{
|
||||
class problem_1006B
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
if (ip[1] == 1)
|
||||
{
|
||||
Console.WriteLine("{0}", a.Max());
|
||||
Console.Write("{0}", ip[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] b = new int[ip[1]];
|
||||
int s = 0;
|
||||
for (int i = 0; i < ip[1]; i++)
|
||||
{
|
||||
int m = a.Max();
|
||||
s += m;
|
||||
b[i] = Array.IndexOf(a, m);
|
||||
a[b[i]] = 0;
|
||||
}
|
||||
Array.Sort(b);
|
||||
Console.WriteLine(s);
|
||||
Console.Write("{0} ", b[0] + 1);
|
||||
for (int i = 1; i < ip[1] - 1; i++)
|
||||
{
|
||||
Console.Write("{0} ", b[i] - b[i - 1]);
|
||||
}
|
||||
Console.Write("{0}", ip[0] - b[ip[1] - 2] - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace problem_1008B
|
||||
{
|
||||
public class problem_1008B
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int c = int.MaxValue;
|
||||
bool b = true;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
if (c >= a.Max())
|
||||
{
|
||||
c = a.Max();
|
||||
}
|
||||
else if ( c >= a.Min())
|
||||
{
|
||||
c = a.Min();
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (b)
|
||||
{
|
||||
Console.Write("YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("NO");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace problem_112A
|
||||
{
|
||||
public class problem_112A
|
||||
{
|
||||
public static int F(char[] c1, char[] c2)
|
||||
{
|
||||
int l = Math.Min(c1.Length, c2.Length);
|
||||
for (int i = 0; i < l; i++)
|
||||
{
|
||||
if (c1[i] < c2[i])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (c1[i] > c2[i])
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (c1.Length > c2.Length)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (c1.Length < c2.Length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
char[] c1 = Console.ReadLine().ToLower().ToCharArray();
|
||||
char[] c2 = Console.ReadLine().ToLower().ToCharArray();
|
||||
Console.Write("{0}", F(c1, c2));
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace _116A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int max = 0, cur = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
cur = cur - a[0] + a[1];
|
||||
if (cur > max)
|
||||
{
|
||||
max = cur;
|
||||
}
|
||||
}
|
||||
Console.WriteLine(max);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace problem_118A
|
||||
{
|
||||
class problem_118A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
char[] r = {'a', 'o', 'y', 'e', 'u', 'i'};
|
||||
string s = Console.ReadLine().ToLower();
|
||||
foreach (char c in r)
|
||||
{
|
||||
s = s.Replace(char.ToString(c), "");
|
||||
}
|
||||
foreach (char c in s)
|
||||
{
|
||||
Console.Write(".{0}", c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _119A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
Console.WriteLine(P(a[0], a[1], a[2]) ? 1 : 0);
|
||||
}
|
||||
static bool P(int a, int b, int c)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int gcd = GCD(a, c);
|
||||
c -= gcd;
|
||||
if (c == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
gcd = GCD(b, c);
|
||||
c -= gcd;
|
||||
if (c == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
static int GCD(int a, int b)
|
||||
{
|
||||
int t;
|
||||
while (b != 0)
|
||||
{
|
||||
t = a % b;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace _122A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
if (n % 4 == 0 || n % 7 == 0 || n % 44 == 0 || n % 47 == 0 || n % 74 == 0 || n % 77 == 0 || n % 444 == 0 || n % 447 == 0 || n % 474 == 0 || n % 477 == 0 || n % 744 == 0 || n % 747 == 0 || n % 774 == 0 || n % 777 == 0)
|
||||
{
|
||||
Console.WriteLine("YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("NO");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace problem_158A
|
||||
{
|
||||
public class problem_158A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] line_1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] line_2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int c = 0;
|
||||
for (int i = 0; i < line_1[0]; i++)
|
||||
{
|
||||
if (line_2[i] >= line_2[line_1[1] - 1] && line_2[i] > 0)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.WriteLine(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace problem_158B
|
||||
{
|
||||
class problem_158B
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = new int[4];
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
a[ip[i] - 1]++;
|
||||
}
|
||||
int c = a[3];
|
||||
c += a[2];
|
||||
a[0] -= a[2];
|
||||
if (a[0] < 0)
|
||||
{
|
||||
a[0] = 0;
|
||||
}
|
||||
c += a[1] / 2;
|
||||
a[1] %= 2;
|
||||
a[0] += 2 * a[1];
|
||||
c += a[0] / 4;
|
||||
if (a[0] % 4 != 0)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
Console.Write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace problem_1A
|
||||
{
|
||||
class problem_1A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string s = Console.ReadLine();
|
||||
string[] input = s.Split(' ');
|
||||
long m = Convert.ToInt32(input[0]);
|
||||
long n = Convert.ToInt32(input[1]);
|
||||
long a = Convert.ToInt32(input[2]);
|
||||
if (a != 0)
|
||||
{
|
||||
if (m % a == 0)
|
||||
{
|
||||
m /= a;
|
||||
}
|
||||
else
|
||||
{
|
||||
m = m / a + 1;
|
||||
}
|
||||
if (n % a == 0)
|
||||
{
|
||||
n /= a;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = n / a + 1;
|
||||
}
|
||||
}
|
||||
Console.WriteLine(m * n);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
|
||||
namespace problem_1B
|
||||
{
|
||||
class problem_1B
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
string s = Console.ReadLine();
|
||||
int pos_R = s.IndexOf('R');
|
||||
int pos_C = s.IndexOf('C');
|
||||
if (pos_R == 0 && pos_C > 1 && char.IsDigit(s[1]))
|
||||
{
|
||||
int r = int.Parse(s.Substring(1, pos_C - 1));
|
||||
int c = int.Parse(s.Substring(pos_C + 1, s.Length - 1 - pos_C));
|
||||
string output = "";
|
||||
while (c > 0)
|
||||
{
|
||||
if (c % 26 == 0)
|
||||
{
|
||||
output += "Z";
|
||||
c = c / 26 - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
output += Convert.ToString(Convert.ToChar('A' + c % 26 - 1));
|
||||
c /= 26;
|
||||
}
|
||||
}
|
||||
for (int j = output.Length - 1; j >= 0; j--)
|
||||
{
|
||||
Console.Write(output[j]);
|
||||
}
|
||||
Console.WriteLine(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
int j = 0;
|
||||
int r = 0;
|
||||
int c = 0;
|
||||
while(char.IsDigit(s[j]) == false)
|
||||
{
|
||||
j++;
|
||||
}
|
||||
r = int.Parse(s.Substring(j, s.Length - j));
|
||||
for (int k = 0; k < j; k++)
|
||||
{
|
||||
c = c * 26 + Convert.ToInt32(s[k]) + 1 - 'A';
|
||||
}
|
||||
Console.WriteLine("R{0}C{1}", r, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace _214A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int i = 0, j = a[0], count = 0;
|
||||
while (i <= a[0] && j >= 0)
|
||||
{
|
||||
if (i + j * j == a[1])
|
||||
{
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
j = a[0] - i * i;
|
||||
}
|
||||
Console.WriteLine(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
|
||||
namespace _217A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] p = new int[n];
|
||||
int[][] a = new int[n][];
|
||||
int c = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
a[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
p[i] = i;
|
||||
}
|
||||
for (int i = 0; i < n - 1; i++)
|
||||
{
|
||||
for (int j = i + 1; j < n; j++)
|
||||
{
|
||||
if (a[i][0] == a[j][0] || a[i][1] == a[j][1])
|
||||
{
|
||||
int ti = p[i];
|
||||
while (ti != p[ti])
|
||||
{
|
||||
ti = p[ti];
|
||||
}
|
||||
int tj = p[j];
|
||||
while (tj != p[tj])
|
||||
{
|
||||
tj = p[tj];
|
||||
}
|
||||
p[tj] = ti;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (i == p[i])
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
Console.WriteLine(c - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
|
||||
namespace problem_224B
|
||||
{
|
||||
class problem_224B
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int count = 0;
|
||||
int[] c = new int[100000];
|
||||
for (int i = 0; i < ip[0]; i++)
|
||||
{
|
||||
if (c[a[i] - 1]++ == 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count < ip[1])
|
||||
{
|
||||
Console.Write("-1 -1");
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
for (i = ip[0] - 1; count >= ip[1]; i--)
|
||||
{
|
||||
if (--c[a[i] - 1] == 0)
|
||||
{
|
||||
count--;
|
||||
}
|
||||
}
|
||||
int r = ++i;
|
||||
c[a[i] - 1]++;
|
||||
count++;
|
||||
for (i = 0; count == ip[1]; i++)
|
||||
{
|
||||
c[a[i] - 1]--;
|
||||
if (c[a[i] - 1] == 0) count--;
|
||||
}
|
||||
int l = --i;
|
||||
c[a[i] - 1]++;
|
||||
count++;
|
||||
Console.Write("{0} {1}", l + 1, r + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
|
||||
namespace problem_230A
|
||||
{
|
||||
class problem_230A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string[] ip;
|
||||
ip = Console.ReadLine().Split(' ');
|
||||
int s = int.Parse(ip[0]);
|
||||
int n = int.Parse(ip[1]);
|
||||
if (C(s, n))
|
||||
{
|
||||
Console.Write("YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("NO");
|
||||
}
|
||||
}
|
||||
static bool C(int s, int n)
|
||||
{
|
||||
int[] a = new int[n];
|
||||
int[] b = new int[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
string[] ip = Console.ReadLine().Split(' ');
|
||||
a[i] = int.Parse(ip[0]);
|
||||
b[i] = int.Parse(ip[1]);
|
||||
}
|
||||
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;
|
||||
t = b[i];
|
||||
b[i] = b[j];
|
||||
b[j] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (s > a[i])
|
||||
{
|
||||
s += b[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace problem_242B
|
||||
{
|
||||
class problem_242B
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = new int[n];
|
||||
int[] b = new int[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
string[] ip = Console.ReadLine().Split(' ');
|
||||
a[i] = int.Parse(ip[0]);
|
||||
b[i] = int.Parse(ip[1]);
|
||||
}
|
||||
int m1 = a.Min();
|
||||
int m2 = b.Max();
|
||||
int c = -1;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (a[i] == m1 && b[i] == m2)
|
||||
{
|
||||
c = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.Write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace problem_246A
|
||||
{
|
||||
class problem_246A
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
if (n < 3)
|
||||
{
|
||||
Console.Write("{0}", -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = n; i > 0; i--)
|
||||
{
|
||||
Console.Write("{0} ", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace problem_266A
|
||||
{
|
||||
public class problem_266A
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
char[] a = Console.ReadLine().ToCharArray();
|
||||
int c = 0;
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
if (a[i] == a[i - 1])
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
Console.Write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _277A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static bool[,] board;
|
||||
static int[] a;
|
||||
static bool[] b;
|
||||
static Queue<int> qi = new Queue<int>();
|
||||
static void Main(string[] args)
|
||||
{
|
||||
a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
board = new bool[a[0], a[1]];
|
||||
b = new bool[a[0]];
|
||||
int count = 0;
|
||||
int c = 0;
|
||||
for (int i = 0; i < a[0]; i++)
|
||||
{
|
||||
int[] array = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
if (array[0] == 0)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
for (int j = 1; j <= array[0]; j++)
|
||||
{
|
||||
board[i, array[j] - 1] = true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
for (int i = 0; i < a[0]; i++)
|
||||
{
|
||||
for (int j = 0; j < a[1]; j++)
|
||||
{
|
||||
Console.Write("{0} ", board[i, j] ? 1 : 0);
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
*/
|
||||
if (c == a[0])
|
||||
{
|
||||
Console.WriteLine(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < a[0]; i++)
|
||||
{
|
||||
if (b[i] == false)
|
||||
{
|
||||
count++;
|
||||
DFS(i);
|
||||
}
|
||||
}
|
||||
Console.WriteLine(count - 1);
|
||||
}
|
||||
}
|
||||
static void DFS(int n)
|
||||
{
|
||||
b[n] = true;
|
||||
qi.Enqueue(n);
|
||||
while (qi.Count != 0)
|
||||
{
|
||||
int t = qi.First();
|
||||
qi.Dequeue();
|
||||
for (int j = 0; j < a[1]; j++)
|
||||
{
|
||||
if (board[t, j] == true)
|
||||
{
|
||||
for (int i = 0; i < a[0]; i++)
|
||||
{
|
||||
if (board[i, j] == true && b[i] == false)
|
||||
{
|
||||
b[i] = true;
|
||||
qi.Enqueue(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace problem_279B
|
||||
{
|
||||
class problem_279B
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int c = 0, s = 0, x = 0;
|
||||
for (int i = 0; i < ip[0]; i++)
|
||||
{
|
||||
s += a[i];
|
||||
c++;
|
||||
if (s > ip[1])
|
||||
{
|
||||
c--;
|
||||
s -= a[x];
|
||||
x++;
|
||||
}
|
||||
}
|
||||
Console.Write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace problem_281A
|
||||
{
|
||||
public class problem_281A
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string ip = Console.ReadLine();
|
||||
ip = char.ToUpper(ip[0]) + ip.Substring(1);
|
||||
Console.Write(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace problem_282A
|
||||
{
|
||||
public class problem_282A
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int x = 0;
|
||||
while (n-- > 0)
|
||||
{
|
||||
string s = Console.ReadLine();
|
||||
if (s.Contains("++"))
|
||||
{
|
||||
x++;
|
||||
}
|
||||
else
|
||||
{
|
||||
x--;
|
||||
}
|
||||
}
|
||||
Console.Write(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace _334B
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] x = new int[8];
|
||||
int[] y = new int[8];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
x[i] = ip[0];
|
||||
y[i] = ip[1];
|
||||
}
|
||||
int[] xx = x.Distinct().ToArray();
|
||||
int[] yy = y.Distinct().ToArray();
|
||||
bool b = false;
|
||||
if (xx.Length == 3 && yy.Length == 3)
|
||||
{
|
||||
Array.Sort(xx);
|
||||
Array.Sort(yy);
|
||||
b = true;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
if (i != 1 || j != 1)
|
||||
{
|
||||
bool c = false;
|
||||
for (int k = 0; k < 8; k++)
|
||||
{
|
||||
if (x[k] == xx[i] && y[k] == yy[j])
|
||||
{
|
||||
c = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
b &= c;
|
||||
}
|
||||
if (b == false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (b == false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b)
|
||||
{
|
||||
Console.WriteLine("respectable");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("ugly");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
namespace problem_339A
|
||||
{
|
||||
public class problem_339A
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split('+'), int.Parse);
|
||||
for (int i = 0; i < a.Length - 1; i++)
|
||||
{
|
||||
for (int j = i + 1; j < a.Length; j++)
|
||||
{
|
||||
if (a[j] < a[i])
|
||||
{
|
||||
int t = a[j];
|
||||
a[j] = a[i];
|
||||
a[i] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.Write("{0}", a[0]);
|
||||
for (int i = 1; i < a.Length; i++)
|
||||
{
|
||||
Console.Write("+{0}", a[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _378B
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a1 = new int[n];
|
||||
int[] a2 = new int[n];
|
||||
int i, j;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
a1[i] = ip[0];
|
||||
a2[i] = ip[1];
|
||||
i++;
|
||||
}
|
||||
i = n / 2;
|
||||
while (a1[i] < a2[n - 1 - i])
|
||||
{
|
||||
i++;
|
||||
if (i == n)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
j = 0;
|
||||
while (j < i)
|
||||
{
|
||||
Console.Write("1");
|
||||
j++;
|
||||
}
|
||||
while (j < n)
|
||||
{
|
||||
Console.Write("0");
|
||||
j++;
|
||||
}
|
||||
Console.WriteLine();
|
||||
i = n / 2;
|
||||
while (a2[i] < a1[n - 1 - i] && i < n)
|
||||
{
|
||||
i++;
|
||||
if (i == n)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
j = 0;
|
||||
while (j < i)
|
||||
{
|
||||
Console.Write("1");
|
||||
j++;
|
||||
}
|
||||
while (j < n)
|
||||
{
|
||||
Console.Write("0");
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace problem_381A
|
||||
{
|
||||
class problem_381A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] b = new int[n];
|
||||
int l = 0, r = n - 1, s1 = 0, s2 = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (a[l] >= a[r])
|
||||
{
|
||||
b[i] = a[l++];
|
||||
}
|
||||
else
|
||||
{
|
||||
b[i] = a[r--];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
s1 += b[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
s2 += b[i];
|
||||
}
|
||||
}
|
||||
Console.Write("{0} {1}", s1, s2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace problem_387B
|
||||
{
|
||||
class problem_387B
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int c = 0;
|
||||
int i = a.Length - 1;
|
||||
for (int j = b.Length - 1; i >= 0 && j >= 0; i--)
|
||||
{
|
||||
if (a[i] <= b[j])
|
||||
{
|
||||
j--;
|
||||
}
|
||||
else
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
if (i != -1)
|
||||
{
|
||||
c += i + 1;
|
||||
}
|
||||
Console.Write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
|
||||
namespace problem_430A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int max = 0;
|
||||
for (int i = 1; i < ip[0]; i++)
|
||||
{
|
||||
if (a[i] != ip[2] || a[i - 1] != ip[2])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int l = i - 2, r = i + 1, cur = 2;
|
||||
while (l >= 0 && r < ip[0])
|
||||
{
|
||||
int tmp = a[r];
|
||||
int t = 0;
|
||||
while (l >= 0 && a[l] == tmp)
|
||||
{
|
||||
l--;
|
||||
t++;
|
||||
}
|
||||
while (r < ip[0] && a[r] == tmp)
|
||||
{
|
||||
r++;
|
||||
t++;
|
||||
}
|
||||
if (t < 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur += t;
|
||||
}
|
||||
}
|
||||
if (cur > max)
|
||||
{
|
||||
max = cur;
|
||||
}
|
||||
}
|
||||
Console.Write(max);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace problem_43A
|
||||
{
|
||||
class problem_43A
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
string t1 = Console.ReadLine();
|
||||
string t2 = "";
|
||||
int c1 = 1, c2 = 0;
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
string t = Console.ReadLine();
|
||||
if (t == t1)
|
||||
{
|
||||
c1++;
|
||||
}
|
||||
else
|
||||
{
|
||||
t2 = t;
|
||||
c2++;
|
||||
}
|
||||
}
|
||||
if (c1 > c2)
|
||||
{
|
||||
Console.Write(t1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write(t2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace _448B
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string s1 = Console.ReadLine();
|
||||
string s2 = Console.ReadLine();
|
||||
char[] c1 = s1.ToCharArray();
|
||||
char[] c2 = s2.ToCharArray();
|
||||
Array.Sort(c1);
|
||||
Array.Sort(c2);
|
||||
if (Cnt(s1, s2) == s2.Length)
|
||||
{
|
||||
Console.WriteLine("automaton");
|
||||
}
|
||||
else if (new string(c1) == new string(c2))
|
||||
{
|
||||
Console.WriteLine("array");
|
||||
}
|
||||
else if (Cnt(new string(c1), new string(c2)) == s2.Length)
|
||||
{
|
||||
Console.WriteLine("both");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("need tree");
|
||||
}
|
||||
}
|
||||
static int Cnt(string s1, string s2)
|
||||
{
|
||||
int id = 0, cnt = 0;
|
||||
for (int i = 0; i < s2.Length; i++)
|
||||
{
|
||||
for (int j = id; j < s1.Length; j++)
|
||||
{
|
||||
if (s1[j] == s2[i])
|
||||
{
|
||||
id = j + 1;
|
||||
cnt++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cnt == s2.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _451B
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int i = 0, c = 0, l = 1, r = 1;
|
||||
bool b = false;
|
||||
while (i < n - 1)
|
||||
{
|
||||
if (a[i] < a[i + 1])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int j = i;
|
||||
while (j < n - 1 && a[j] > a[j + 1])
|
||||
{
|
||||
j++;
|
||||
}
|
||||
l = i + 1;
|
||||
r = j + 1;
|
||||
c++;
|
||||
i = r;
|
||||
}
|
||||
}
|
||||
if (c < 2)
|
||||
{
|
||||
int c1 = l > 1 ? a[l - 2] : 0;
|
||||
int c2 = r < n ? a[r] : int.MaxValue;
|
||||
if (a[r - 1] > c1 && a[l - 1] < c2)
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
|
||||
}
|
||||
if (b)
|
||||
{
|
||||
Console.WriteLine("yes");
|
||||
Console.WriteLine("{0} {1}", l, r);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("no");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace _466A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int b = a[0] * a[2];
|
||||
int c = (a[0] % a[1] == 0) ? a[0] / a[1] * a[3] : (a[0] / a[1] + 1) * a[3];
|
||||
int d = a[0] / a[1] * a[3] + (a[0] % a[1]) * a[2];
|
||||
Console.WriteLine(Math.Min(b, Math.Min(c, d)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace _467A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int count = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
if (a[1] - a[0] > 1)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Console.WriteLine(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace problem_474A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string s = "qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
|
||||
string c = Console.ReadLine();
|
||||
string ip = Console.ReadLine();
|
||||
string op = "";
|
||||
if (c == "R")
|
||||
{
|
||||
for (int i = 0; i < ip.Length; i++)
|
||||
{
|
||||
int p = s.IndexOf(ip[i]);
|
||||
if (p != -1)
|
||||
{
|
||||
op += s[p - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < ip.Length; i++)
|
||||
{
|
||||
int p = s.IndexOf(ip[i]);
|
||||
if (p != -1)
|
||||
{
|
||||
op += s[p + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine(op);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace _478A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
sum += a[i];
|
||||
}
|
||||
Console.WriteLine((sum % 5 == 0 && sum != 0) ? sum / 5 : -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace _479A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int a = int.Parse(Console.ReadLine());
|
||||
int b = int.Parse(Console.ReadLine());
|
||||
int c = int.Parse(Console.ReadLine());
|
||||
Console.WriteLine(Math.Max(a + b + c, Math.Max(a * b * c, Math.Max(a + b * c, Math.Max(a * b + c, Math.Max((a + b) * c, a * (b + c)))))));
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace _486A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
ulong n = ulong.Parse(Console.ReadLine());
|
||||
Console.WriteLine(n % 2 == 0 ? (n / 2).ToString() : "-" + ((n + 1) / 2).ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace _492A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int a = 0, b = 0, c = 0;
|
||||
while (n > c)
|
||||
{
|
||||
a++;
|
||||
b = a * (a + 1) / 2;
|
||||
c += b;
|
||||
}
|
||||
Console.WriteLine(c > n ? a - 1 : a);
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace _499B
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
bool[] b = new bool[a[1]];
|
||||
string[] s1 = new string[a[1]];
|
||||
string[] s2 = new string[a[1]];
|
||||
for (int i = 0; i < a[1]; i++)
|
||||
{
|
||||
string[] ip = Console.ReadLine().Split(' ');
|
||||
s1[i] = ip[0];
|
||||
s2[i] = ip[1];
|
||||
if (s2[i].Length < s1[i].Length)
|
||||
{
|
||||
b[i] = true;
|
||||
}
|
||||
}
|
||||
string[] s = Console.ReadLine().Split(' ');
|
||||
for (int i = 0; i < a[0]; i++)
|
||||
{
|
||||
int p = Array.IndexOf(s1, s[i]);
|
||||
if (b[p])
|
||||
{
|
||||
s[i] = s2[p];
|
||||
}
|
||||
}
|
||||
foreach (string t in s)
|
||||
{
|
||||
Console.Write("{0} ", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace problem_4A
|
||||
{
|
||||
class problem_4A
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
if (n > 2 && n%2 == 0)
|
||||
{
|
||||
Console.Write("YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("NO");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace problem_50A
|
||||
{
|
||||
class problem_50A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
|
||||
Console.WriteLine("{0}", a[0] * a[1] / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user