diff --git a/cpp/110A.cpp b/cpp/110A.cpp new file mode 100644 index 0000000..a9d2346 --- /dev/null +++ b/cpp/110A.cpp @@ -0,0 +1,27 @@ +#include +#include + +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; +} diff --git a/cpp/112A.cpp b/cpp/112A.cpp new file mode 100644 index 0000000..db59ad6 --- /dev/null +++ b/cpp/112A.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +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; +} diff --git a/cpp/118A.cpp b/cpp/118A.cpp new file mode 100644 index 0000000..281c951 --- /dev/null +++ b/cpp/118A.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +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; +} diff --git a/cpp/122A.cpp b/cpp/122A.cpp new file mode 100644 index 0000000..d8dad7a --- /dev/null +++ b/cpp/122A.cpp @@ -0,0 +1,16 @@ +#include + +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; +} diff --git a/cpp/133A.cpp b/cpp/133A.cpp new file mode 100644 index 0000000..df0b455 --- /dev/null +++ b/cpp/133A.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +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; +} diff --git a/cpp/136A.cpp b/cpp/136A.cpp new file mode 100644 index 0000000..35504fc --- /dev/null +++ b/cpp/136A.cpp @@ -0,0 +1,28 @@ +#include + +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; +} diff --git a/cpp/144A.cpp b/cpp/144A.cpp new file mode 100644 index 0000000..fc06795 --- /dev/null +++ b/cpp/144A.cpp @@ -0,0 +1,34 @@ +#include + +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; +} diff --git a/cpp/148A.cpp b/cpp/148A.cpp new file mode 100644 index 0000000..8fb32f3 --- /dev/null +++ b/cpp/148A.cpp @@ -0,0 +1,18 @@ +#include + +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; +} diff --git a/cpp/158A.cpp b/cpp/158A.cpp new file mode 100644 index 0000000..1612f99 --- /dev/null +++ b/cpp/158A.cpp @@ -0,0 +1,23 @@ +#include + +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; +} diff --git a/cpp/158B.cpp b/cpp/158B.cpp new file mode 100644 index 0000000..76790e4 --- /dev/null +++ b/cpp/158B.cpp @@ -0,0 +1,59 @@ +#include + +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; +} diff --git a/cpp/160A.cpp b/cpp/160A.cpp new file mode 100644 index 0000000..611e75c --- /dev/null +++ b/cpp/160A.cpp @@ -0,0 +1,33 @@ +#include + +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; +} diff --git a/cpp/1A.cpp b/cpp/1A.cpp new file mode 100644 index 0000000..aa4ce0d --- /dev/null +++ b/cpp/1A.cpp @@ -0,0 +1,11 @@ +#include + +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; +} diff --git a/cpp/200B.cpp b/cpp/200B.cpp new file mode 100644 index 0000000..548d052 --- /dev/null +++ b/cpp/200B.cpp @@ -0,0 +1,27 @@ +#include +#include + +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; +} \ No newline at end of file diff --git a/cpp/228A.cpp b/cpp/228A.cpp new file mode 100644 index 0000000..404a82f --- /dev/null +++ b/cpp/228A.cpp @@ -0,0 +1,18 @@ +#include + +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; +} diff --git a/cpp/236A.cpp b/cpp/236A.cpp new file mode 100644 index 0000000..17dba33 --- /dev/null +++ b/cpp/236A.cpp @@ -0,0 +1,27 @@ +#include +#include + +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; +} diff --git a/cpp/25A.cpp b/cpp/25A.cpp new file mode 100644 index 0000000..6535119 --- /dev/null +++ b/cpp/25A.cpp @@ -0,0 +1,35 @@ +#include +#include + +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; +} diff --git a/cpp/263A.cpp b/cpp/263A.cpp new file mode 100644 index 0000000..533ffdc --- /dev/null +++ b/cpp/263A.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +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; +} diff --git a/cpp/266A.cpp b/cpp/266A.cpp new file mode 100644 index 0000000..8272ebf --- /dev/null +++ b/cpp/266A.cpp @@ -0,0 +1,25 @@ +#include + +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; +} diff --git a/cpp/266B.cpp b/cpp/266B.cpp new file mode 100644 index 0000000..0f9faca --- /dev/null +++ b/cpp/266B.cpp @@ -0,0 +1,26 @@ +#include +#include + +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; +} diff --git a/cpp/268A.cpp b/cpp/268A.cpp new file mode 100644 index 0000000..8f77735 --- /dev/null +++ b/cpp/268A.cpp @@ -0,0 +1,31 @@ +#include + +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; +} diff --git a/cpp/271A.cpp b/cpp/271A.cpp new file mode 100644 index 0000000..0215535 --- /dev/null +++ b/cpp/271A.cpp @@ -0,0 +1,36 @@ +#include + +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; +} diff --git a/cpp/281A.cpp b/cpp/281A.cpp new file mode 100644 index 0000000..fb68241 --- /dev/null +++ b/cpp/281A.cpp @@ -0,0 +1,16 @@ +#include +#include + +using namespace std; + +int main() +{ + string s; + cin >> s; + if (islower(s[0])) + { + s[0] = toupper(s[0]); + } + cout << s << endl; + return 0; +} diff --git a/cpp/282A.cpp b/cpp/282A.cpp new file mode 100644 index 0000000..568888d --- /dev/null +++ b/cpp/282A.cpp @@ -0,0 +1,25 @@ +#include +#include + +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; +} diff --git a/cpp/318A.cpp b/cpp/318A.cpp new file mode 100644 index 0000000..957329b --- /dev/null +++ b/cpp/318A.cpp @@ -0,0 +1,30 @@ +#include + +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; +} diff --git a/cpp/337A.cpp b/cpp/337A.cpp new file mode 100644 index 0000000..e68a614 --- /dev/null +++ b/cpp/337A.cpp @@ -0,0 +1,38 @@ +#include + +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; +} diff --git a/cpp/339A.cpp b/cpp/339A.cpp new file mode 100644 index 0000000..94e1f6e --- /dev/null +++ b/cpp/339A.cpp @@ -0,0 +1,43 @@ +#include +#include + +#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; +} diff --git a/cpp/339B.cpp b/cpp/339B.cpp new file mode 100644 index 0000000..6f46238 --- /dev/null +++ b/cpp/339B.cpp @@ -0,0 +1,26 @@ +#include + +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; +} diff --git a/cpp/344A.cpp b/cpp/344A.cpp new file mode 100644 index 0000000..5fb74d7 --- /dev/null +++ b/cpp/344A.cpp @@ -0,0 +1,24 @@ +#include + +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; +} diff --git a/cpp/379A.cpp b/cpp/379A.cpp new file mode 100644 index 0000000..60838ef --- /dev/null +++ b/cpp/379A.cpp @@ -0,0 +1,23 @@ +#include + +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; +} diff --git a/cpp/405A.cpp b/cpp/405A.cpp new file mode 100644 index 0000000..c558cef --- /dev/null +++ b/cpp/405A.cpp @@ -0,0 +1,33 @@ +#include + +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; +} diff --git a/cpp/41A.cpp b/cpp/41A.cpp new file mode 100644 index 0000000..42562f5 --- /dev/null +++ b/cpp/41A.cpp @@ -0,0 +1,35 @@ +#include +#include + +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; +} diff --git a/cpp/443A.cpp b/cpp/443A.cpp new file mode 100644 index 0000000..4f79b8e --- /dev/null +++ b/cpp/443A.cpp @@ -0,0 +1,20 @@ +#include +#include + +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; +} diff --git a/cpp/451A.cpp b/cpp/451A.cpp new file mode 100644 index 0000000..6c8f033 --- /dev/null +++ b/cpp/451A.cpp @@ -0,0 +1,22 @@ +#include + +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; +} diff --git a/cpp/467A.cpp b/cpp/467A.cpp new file mode 100644 index 0000000..77314ff --- /dev/null +++ b/cpp/467A.cpp @@ -0,0 +1,21 @@ +#include + +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; +} diff --git a/cpp/469A.cpp b/cpp/469A.cpp new file mode 100644 index 0000000..589e040 --- /dev/null +++ b/cpp/469A.cpp @@ -0,0 +1,51 @@ +#include + +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; +} diff --git a/cpp/472A.cpp b/cpp/472A.cpp new file mode 100644 index 0000000..9d64762 --- /dev/null +++ b/cpp/472A.cpp @@ -0,0 +1,35 @@ +#include + +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; +} diff --git a/cpp/479A.cpp b/cpp/479A.cpp new file mode 100644 index 0000000..ddfa932 --- /dev/null +++ b/cpp/479A.cpp @@ -0,0 +1,26 @@ +#include + +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; +} diff --git a/cpp/4A.cpp b/cpp/4A.cpp new file mode 100644 index 0000000..b5f6b8f --- /dev/null +++ b/cpp/4A.cpp @@ -0,0 +1,18 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + if (n%2 || n <= 2) + { + cout << "NO" << endl; + } + else + { + cout << "YES" << endl; + } + return 0; +} diff --git a/cpp/500A.cpp b/cpp/500A.cpp new file mode 100644 index 0000000..00156d6 --- /dev/null +++ b/cpp/500A.cpp @@ -0,0 +1,30 @@ +#include + +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; +} diff --git a/cpp/510A.cpp b/cpp/510A.cpp new file mode 100644 index 0000000..94c161e --- /dev/null +++ b/cpp/510A.cpp @@ -0,0 +1,37 @@ +#include + +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; +} diff --git a/cpp/520A.cpp b/cpp/520A.cpp new file mode 100644 index 0000000..ca8905e --- /dev/null +++ b/cpp/520A.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +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; +} diff --git a/cpp/58A.cpp b/cpp/58A.cpp new file mode 100644 index 0000000..668d018 --- /dev/null +++ b/cpp/58A.cpp @@ -0,0 +1,38 @@ +#include +#include + +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; +} diff --git a/cpp/59A.cpp b/cpp/59A.cpp new file mode 100644 index 0000000..f3bd374 --- /dev/null +++ b/cpp/59A.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +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; +} diff --git a/cpp/600B.cpp b/cpp/600B.cpp new file mode 100644 index 0000000..380437a --- /dev/null +++ b/cpp/600B.cpp @@ -0,0 +1,19 @@ +#include +#include +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; +} \ No newline at end of file diff --git a/cpp/617A.cpp b/cpp/617A.cpp new file mode 100644 index 0000000..88e42b1 --- /dev/null +++ b/cpp/617A.cpp @@ -0,0 +1,18 @@ +#include + +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; +} diff --git a/cpp/61A.cpp b/cpp/61A.cpp new file mode 100644 index 0000000..db6380f --- /dev/null +++ b/cpp/61A.cpp @@ -0,0 +1,21 @@ +#include + +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; +} diff --git a/cpp/677A.cpp b/cpp/677A.cpp new file mode 100644 index 0000000..c3a95e1 --- /dev/null +++ b/cpp/677A.cpp @@ -0,0 +1,20 @@ +#include + +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; +} diff --git a/cpp/69A.cpp b/cpp/69A.cpp new file mode 100644 index 0000000..7a806c4 --- /dev/null +++ b/cpp/69A.cpp @@ -0,0 +1,29 @@ +#include + +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; +} diff --git a/cpp/71A.cpp b/cpp/71A.cpp new file mode 100644 index 0000000..930fb81 --- /dev/null +++ b/cpp/71A.cpp @@ -0,0 +1,24 @@ +#include +#include + +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; +} diff --git a/cpp/734A.cpp b/cpp/734A.cpp new file mode 100644 index 0000000..3f0cfcb --- /dev/null +++ b/cpp/734A.cpp @@ -0,0 +1,38 @@ +#include +#include + +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; +} diff --git a/cpp/82A.cpp b/cpp/82A.cpp new file mode 100644 index 0000000..dbf46e4 --- /dev/null +++ b/cpp/82A.cpp @@ -0,0 +1,25 @@ +#include + +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; +} diff --git a/cpp/96A.cpp b/cpp/96A.cpp new file mode 100644 index 0000000..ba29f91 --- /dev/null +++ b/cpp/96A.cpp @@ -0,0 +1,19 @@ +#include +#include + +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; +} diff --git a/cpp/992A.cpp b/cpp/992A.cpp new file mode 100644 index 0000000..0e83a1c --- /dev/null +++ b/cpp/992A.cpp @@ -0,0 +1,27 @@ +#include + +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; +} diff --git a/cpp/994A.cpp b/cpp/994A.cpp new file mode 100644 index 0000000..9ba041d --- /dev/null +++ b/cpp/994A.cpp @@ -0,0 +1,32 @@ +#include + +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; +} diff --git a/cs/1000A.cs b/cs/1000A.cs new file mode 100644 index 0000000..d11683e --- /dev/null +++ b/cs/1000A.cs @@ -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 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); + } + } +} \ No newline at end of file diff --git a/cs/1004A.cs b/cs/1004A.cs new file mode 100644 index 0000000..94f9858 --- /dev/null +++ b/cs/1004A.cs @@ -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); + } + } +} diff --git a/cs/1004B.cs b/cs/1004B.cs new file mode 100644 index 0000000..25ed9f3 --- /dev/null +++ b/cs/1004B.cs @@ -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"); + } + } + } + } +} diff --git a/cs/1005A.cs b/cs/1005A.cs new file mode 100644 index 0000000..91a034e --- /dev/null +++ b/cs/1005A.cs @@ -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); + } + } + } +} \ No newline at end of file diff --git a/cs/1006A.cs b/cs/1006A.cs new file mode 100644 index 0000000..c821588 --- /dev/null +++ b/cs/1006A.cs @@ -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); + } + } + } +} diff --git a/cs/1006B.cs b/cs/1006B.cs new file mode 100644 index 0000000..ec1f5ff --- /dev/null +++ b/cs/1006B.cs @@ -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); + } + } + } +} diff --git a/cs/1008B.cs b/cs/1008B.cs new file mode 100644 index 0000000..f729aa5 --- /dev/null +++ b/cs/1008B.cs @@ -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"); + } + } + } +} diff --git a/cs/112A.cs b/cs/112A.cs new file mode 100644 index 0000000..fcc6c08 --- /dev/null +++ b/cs/112A.cs @@ -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)); + } + } +} diff --git a/cs/116A.cs b/cs/116A.cs new file mode 100644 index 0000000..3017a04 --- /dev/null +++ b/cs/116A.cs @@ -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); + } + } +} diff --git a/cs/118A.cs b/cs/118A.cs new file mode 100644 index 0000000..c798a97 --- /dev/null +++ b/cs/118A.cs @@ -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); + } + } + } +} diff --git a/cs/119A.cs b/cs/119A.cs new file mode 100644 index 0000000..60ace03 --- /dev/null +++ b/cs/119A.cs @@ -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; + } + } +} diff --git a/cs/122A.cs b/cs/122A.cs new file mode 100644 index 0000000..f85d7dd --- /dev/null +++ b/cs/122A.cs @@ -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"); + } + } + } +} diff --git a/cs/158A.cs b/cs/158A.cs new file mode 100644 index 0000000..0365b3a --- /dev/null +++ b/cs/158A.cs @@ -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); + } + } +} diff --git a/cs/158B.cs b/cs/158B.cs new file mode 100644 index 0000000..b4077ce --- /dev/null +++ b/cs/158B.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/cs/1A.cs b/cs/1A.cs new file mode 100644 index 0000000..28bd214 --- /dev/null +++ b/cs/1A.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/cs/1B.cs b/cs/1B.cs new file mode 100644 index 0000000..53899b1 --- /dev/null +++ b/cs/1B.cs @@ -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); + } + } + } + } +} \ No newline at end of file diff --git a/cs/214A.cs b/cs/214A.cs new file mode 100644 index 0000000..1b8e656 --- /dev/null +++ b/cs/214A.cs @@ -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); + } + } +} diff --git a/cs/217A.cs b/cs/217A.cs new file mode 100644 index 0000000..2fe1c1a --- /dev/null +++ b/cs/217A.cs @@ -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); + } + } +} diff --git a/cs/224B.cs b/cs/224B.cs new file mode 100644 index 0000000..bd24c42 --- /dev/null +++ b/cs/224B.cs @@ -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); + } + } + } +} diff --git a/cs/230A.cs b/cs/230A.cs new file mode 100644 index 0000000..c5129f5 --- /dev/null +++ b/cs/230A.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/cs/242B.cs b/cs/242B.cs new file mode 100644 index 0000000..46c4427 --- /dev/null +++ b/cs/242B.cs @@ -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); + } + } +} diff --git a/cs/246A.cs b/cs/246A.cs new file mode 100644 index 0000000..14e95b0 --- /dev/null +++ b/cs/246A.cs @@ -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); + } + } + } + } +} diff --git a/cs/266A.cs b/cs/266A.cs new file mode 100644 index 0000000..2ab35a2 --- /dev/null +++ b/cs/266A.cs @@ -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); + } + } +} diff --git a/cs/277A.cs b/cs/277A.cs new file mode 100644 index 0000000..c75733d --- /dev/null +++ b/cs/277A.cs @@ -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 qi = new Queue(); + 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); + } + } + } + } + } + } + } +} diff --git a/cs/279B.cs b/cs/279B.cs new file mode 100644 index 0000000..5303681 --- /dev/null +++ b/cs/279B.cs @@ -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); + } + } +} diff --git a/cs/281A.cs b/cs/281A.cs new file mode 100644 index 0000000..eb158f8 --- /dev/null +++ b/cs/281A.cs @@ -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); + } + } +} diff --git a/cs/282A.cs b/cs/282A.cs new file mode 100644 index 0000000..6d977e0 --- /dev/null +++ b/cs/282A.cs @@ -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); + } + } +} diff --git a/cs/334B.cs b/cs/334B.cs new file mode 100644 index 0000000..1eb0eb3 --- /dev/null +++ b/cs/334B.cs @@ -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"); + } + } + } +} diff --git a/cs/339A.cs b/cs/339A.cs new file mode 100644 index 0000000..1f6f05b --- /dev/null +++ b/cs/339A.cs @@ -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]); + } + } + } +} diff --git a/cs/378B.cs b/cs/378B.cs new file mode 100644 index 0000000..6c59b87 --- /dev/null +++ b/cs/378B.cs @@ -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++; + } + } + } +} diff --git a/cs/381A.cs b/cs/381A.cs new file mode 100644 index 0000000..b592193 --- /dev/null +++ b/cs/381A.cs @@ -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); + } + } +} diff --git a/cs/387B.cs b/cs/387B.cs new file mode 100644 index 0000000..3e56771 --- /dev/null +++ b/cs/387B.cs @@ -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); + } + } +} diff --git a/cs/430B.cs b/cs/430B.cs new file mode 100644 index 0000000..89db5af --- /dev/null +++ b/cs/430B.cs @@ -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); + } + } +} diff --git a/cs/43A.cs b/cs/43A.cs new file mode 100644 index 0000000..1cd5cd0 --- /dev/null +++ b/cs/43A.cs @@ -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); + } + } + } +} diff --git a/cs/448B.cs b/cs/448B.cs new file mode 100644 index 0000000..551b2c0 --- /dev/null +++ b/cs/448B.cs @@ -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; + } + } +} diff --git a/cs/451B.cs b/cs/451B.cs new file mode 100644 index 0000000..1268356 --- /dev/null +++ b/cs/451B.cs @@ -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"); + } + } + } +} diff --git a/cs/466A.cs b/cs/466A.cs new file mode 100644 index 0000000..4546617 --- /dev/null +++ b/cs/466A.cs @@ -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))); + } + } +} diff --git a/cs/467A.cs b/cs/467A.cs new file mode 100644 index 0000000..20f6ff6 --- /dev/null +++ b/cs/467A.cs @@ -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); + } + } +} diff --git a/cs/474A.cs b/cs/474A.cs new file mode 100644 index 0000000..7aeb2cf --- /dev/null +++ b/cs/474A.cs @@ -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); + } + } +} diff --git a/cs/478A.cs b/cs/478A.cs new file mode 100644 index 0000000..006fd0a --- /dev/null +++ b/cs/478A.cs @@ -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); + } + } +} diff --git a/cs/479A.cs b/cs/479A.cs new file mode 100644 index 0000000..b4522d5 --- /dev/null +++ b/cs/479A.cs @@ -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))))))); + } + } +} diff --git a/cs/486A.cs b/cs/486A.cs new file mode 100644 index 0000000..d31514d --- /dev/null +++ b/cs/486A.cs @@ -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()); + } + } +} diff --git a/cs/492A.cs b/cs/492A.cs new file mode 100644 index 0000000..6732884 --- /dev/null +++ b/cs/492A.cs @@ -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); + } + } +} diff --git a/cs/499B.cs b/cs/499B.cs new file mode 100644 index 0000000..70d2930 --- /dev/null +++ b/cs/499B.cs @@ -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); + } + } + } +} diff --git a/cs/4A.cs b/cs/4A.cs new file mode 100644 index 0000000..ce09d7d --- /dev/null +++ b/cs/4A.cs @@ -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"); + } + } + } +} \ No newline at end of file diff --git a/cs/50A.cs b/cs/50A.cs new file mode 100644 index 0000000..acc3694 --- /dev/null +++ b/cs/50A.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/cs/510A.cs b/cs/510A.cs new file mode 100644 index 0000000..55cda8c --- /dev/null +++ b/cs/510A.cs @@ -0,0 +1,40 @@ +using System; + +namespace problem_510A +{ + class problem_510A + { + static void Main(string[] args) + { + int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + for (int i = 0; i < ip[0]; i++) + { + switch (i % 4) + { + case 1: + for (int j = 1; j < ip[1]; j++) + { + Console.Write("."); + } + Console.WriteLine("#"); + break; + case 3: + Console.Write("#"); + for (int j = 1; j < ip[1]; j++) + { + Console.Write("."); + } + Console.WriteLine(); + break; + default: + for (int j = 0; j < ip[1]; j++) + { + Console.Write("#"); + } + Console.WriteLine(); + break; + } + } + } + } +} diff --git a/cs/518A.cs b/cs/518A.cs new file mode 100644 index 0000000..648561e --- /dev/null +++ b/cs/518A.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _518A +{ + class Program + { + static void Main(string[] args) + { + string c1 = Console.ReadLine(); + string c2 = Console.ReadLine(); + StringBuilder s1 = new StringBuilder(c1); + StringBuilder s2 = new StringBuilder(c2); + bool b; + if (s1.ToString() == s2.ToString()) + { + b = false; + } + else + { + int j = s1.Length - 1; + for (; j >= 0; j--) + { + if (s1[j] == 'z') + { + s1[j] = 'a'; + } + else + { + s1[j] = Convert.ToChar(s1[j] + 1); + break; + } + } + if (j == -1 || s1.ToString() == s2.ToString()) + { + b = false; + } + else + { + b = true; + } + } + if (b) + { + Console.WriteLine(s1); + } + else + { + Console.WriteLine("No such string"); + } + } + } +} diff --git a/cs/518B.cs b/cs/518B.cs new file mode 100644 index 0000000..19888d6 --- /dev/null +++ b/cs/518B.cs @@ -0,0 +1,44 @@ +using System; + +namespace _518B +{ + class Program + { + static void Main(string[] args) + { + string s = Console.ReadLine(); + string t = Console.ReadLine(); + int[] c1 = new int[52]; + int[] c2 = new int[52]; + for (int i = 0; i < s.Length; i++) + { + if (char.IsLower(s[i])) + { + c1[s[i] - 'a']++; + } + else + { + c1[s[i] - 'A' + 26]++; + } + } + for (int i = 0; i < t.Length; i++) + { + if (char.IsLower(t[i])) + { + c2[t[i] - 'a']++; + } + else + { + c2[t[i] - 'A' + 26]++; + } + } + int y = 0, w = 0; + for (int i = 0; i < 26; i++) + { + y += Math.Min(c1[i], c2[i]) + Math.Min(c1[i + 26], c2[i + 26]); + w += Math.Min(Math.Max(c1[i] - c2[i], 0), Math.Max(c2[i + 26] - c1[i + 26], 0)) + Math.Min(Math.Max(c1[i + 26] - c2[i + 26], 0), Math.Max(c2[i] - c1[i], 0)); + } + Console.WriteLine("{0} {1}", y, w); + } + } +} diff --git a/cs/520A.cs b/cs/520A.cs new file mode 100644 index 0000000..5211132 --- /dev/null +++ b/cs/520A.cs @@ -0,0 +1,26 @@ +using System; + +namespace _520A +{ + class Program + { + static string c = "abcdefghijklmnopqrstuvwxyz"; + static bool Check(string s) + { + for (int i = 0; i < 26; i++) + { + if (s.IndexOf(c[i]) == -1) + { + return false; + } + } + return true; + } + static void Main(string[] args) + { + string s = Console.ReadLine(); + s = Console.ReadLine().ToLower(); + Console.WriteLine("{0}", Check(s) ? "YES" : "NO"); + } + } +} diff --git a/cs/546A.cs b/cs/546A.cs new file mode 100644 index 0000000..2a06899 --- /dev/null +++ b/cs/546A.cs @@ -0,0 +1,13 @@ +using System; + +namespace _546A +{ + class Program + { + static void Main(string[] args) + { + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + Console.WriteLine("{0}", Math.Max(a[0] * a[2] * (a[2] + 1) / 2 - a[1], 0)); + } + } +} diff --git a/cs/557B.cs b/cs/557B.cs new file mode 100644 index 0000000..2ad5421 --- /dev/null +++ b/cs/557B.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _557B +{ + class Program + { + static void Main(string[] args) + { + int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + double[] a = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); + Array.Sort(a); + Console.WriteLine(Math.Min(ip[1], ip[0] * Math.Min(a[0] * 3, a[ip[0]] * 3 / 2)).ToString(".##########").Replace(",", ".")); + } + } +} diff --git a/cs/572A.cs b/cs/572A.cs new file mode 100644 index 0000000..01b5f88 --- /dev/null +++ b/cs/572A.cs @@ -0,0 +1,26 @@ +using System; +using System.Linq; + +namespace problem_572A +{ + class problem_572A + { + public static void Main(string[] args) + { + int[] ip1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int[] ip2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int[] ip3 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int[] ip4 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + Array.Sort(ip3); + Array.Sort(ip4); + if (ip3[ip2[0] - 1] < ip4[ip1[1] - ip2[1]]) + { + Console.Write("YES"); + } + else + { + Console.Write("NO"); + } + } + } +} diff --git a/cs/600B.cs b/cs/600B.cs new file mode 100644 index 0000000..7861306 --- /dev/null +++ b/cs/600B.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _600B +{ + class Program + { + static int FindFirstIndexGreaterThanOrEqualTo(ref List sortedCollection, int key) + { + int begin = 0; + int end = sortedCollection.Count; + while (end > begin) + { + int index = (begin + end) / 2; + int el = sortedCollection[index]; + if (el > key) + end = index; + else + begin = index + 1; + } + return end; + } + static void Main(string[] args) + { + string s = Console.ReadLine(); + //int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + //int[] b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + List a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); + List b = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); + a.Sort(); + for (int i = 0; i < b.Count; i++) + { + Console.Write("{0} ", FindFirstIndexGreaterThanOrEqualTo(ref a, b[i])); + } + } + } +} diff --git a/cs/602B.cs b/cs/602B.cs new file mode 100644 index 0000000..e5b73dd --- /dev/null +++ b/cs/602B.cs @@ -0,0 +1,51 @@ +using System; +using System.Linq; + +namespace _602B +{ + class Program + { + static void Main(string[] args) + { + int n = int.Parse(Console.ReadLine()); + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int[] b = a.ToArray(); + int[] c = a.ToArray(); + int c1 = 1, c2 = 1, max = 1; + for (int i = 0; i < n; i++) + { + if (a[i] % 2 == 1) + { + b[i]++; + } + else + { + c[i]++; + } + } + for (int i = 1; i < n; i++) + { + if (b[i] == b[i - 1]) + { + c1++; + } + else + { + max = Math.Max(max, c1); + c1 = 1; + } + if (c[i] == c[i - 1]) + { + c2++; + } + else + { + max = Math.Max(max, c2); + c2 = 1; + } + } + max = Math.Max(Math.Max(c1, c2), max); + Console.WriteLine(max); + } + } +} diff --git a/cs/609B.cs b/cs/609B.cs new file mode 100644 index 0000000..305e03f --- /dev/null +++ b/cs/609B.cs @@ -0,0 +1,27 @@ +using System; + +namespace problem_609A +{ + class problem_609A + { + public static void Main(string[] args) + { + int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int[] a = new int[ip[1]]; + int[] b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + for (int i = 0; i < ip[0]; i++) + { + a[b[i] - 1]++; + } + long op = 0; + for (int i = 0; i < ip[1] - 1; i++) + { + for (int j = i + 1; j < ip[1]; j++) + { + op += a[i] * a[j]; + } + } + Console.Write("{0}", op); + } + } +} diff --git a/cs/617A.cs b/cs/617A.cs new file mode 100644 index 0000000..8058eb1 --- /dev/null +++ b/cs/617A.cs @@ -0,0 +1,13 @@ +using System; + +namespace _617A +{ + class Program + { + static void Main(string[] args) + { + int n = int.Parse(Console.ReadLine()); + Console.WriteLine(n % 5 == 0 ? n / 5 : n / 5 + 1); + } + } +} diff --git a/cs/61B.cs b/cs/61B.cs new file mode 100644 index 0000000..49bbc64 --- /dev/null +++ b/cs/61B.cs @@ -0,0 +1,35 @@ +using System; + +namespace _61B +{ + class Program + { + static void Main(string[] args) + { + string[] c = new string[3]; + for (int i = 0; i < 3; i++) + { + c[i] = Console.ReadLine().Replace("-", "").Replace(";", "").Replace("_", "").ToLower(); + } + string s1 = c[0] + c[1] + c[2]; + string s2 = c[0] + c[2] + c[1]; + string s3 = c[1] + c[2] + c[0]; + string s4 = c[1] + c[0] + c[2]; + string s5 = c[2] + c[0] + c[1]; + string s6 = c[2] + c[1] + c[0]; + int n = int.Parse(Console.ReadLine()); + for (int i = 0; i < n; i++) + { + string s = Console.ReadLine().Replace("-", "").Replace(";", "").Replace("_", "").ToLower(); + if (s == s1 || s == s2 || s == s3 || s == s4 || s == s5 || s == s6) + { + Console.WriteLine("ACC"); + } + else + { + Console.WriteLine("WA"); + } + } + } + } +} diff --git a/cs/673A.cs b/cs/673A.cs new file mode 100644 index 0000000..03c9bdf --- /dev/null +++ b/cs/673A.cs @@ -0,0 +1,27 @@ +using System; + +namespace problem_673A +{ + class problem_673A + { + public static void Main(string[] args) + { + int n = int.Parse(Console.ReadLine()); + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int l = 15; + for (int i = 0; i < n; i++) + { + if (a[i] <= l) + { + l = a[i] + 15; + } + else + { + break; + } + } + l = Math.Min(l, 90); + Console.Write(l); + } + } +} diff --git a/cs/676A.cs b/cs/676A.cs new file mode 100644 index 0000000..664dff9 --- /dev/null +++ b/cs/676A.cs @@ -0,0 +1,17 @@ +using System; +using System.Linq; + +namespace problem_676A +{ + class problem_676A + { + public static void Main(string[] args) + { + int n = int.Parse(Console.ReadLine()); + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int p1 = Array.IndexOf(a, a.Min()); + int p2 = Array.IndexOf(a, a.Max()); + Console.Write("{0}", new[] { p1, p2, n - 1 - p1, n - 1 - p2 }.Max()); + } + } +} diff --git a/cs/691A.cs b/cs/691A.cs new file mode 100644 index 0000000..7d8ee31 --- /dev/null +++ b/cs/691A.cs @@ -0,0 +1,21 @@ +using System; + +namespace problem_691A +{ + class problem_691A + { + public static void Main(string[] args) + { + Console.ReadLine(); + string s = Console.ReadLine(); + if ((s.IndexOf('0') == s.LastIndexOf('0') && s.Contains("0") && s.Contains("1")) || s == "1") + { + Console.Write("YES"); + } + else + { + Console.Write("NO"); + } + } + } +} diff --git a/cs/721B.cs b/cs/721B.cs new file mode 100644 index 0000000..987557a --- /dev/null +++ b/cs/721B.cs @@ -0,0 +1,22 @@ +using System; + +namespace _721B +{ + class Program + { + static void Main(string[] args) + { + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int[] l = new int[a[0]]; + for (int i = 0; i < a[0]; i++) + { + l[i] = Console.ReadLine().Length; + } + int lp = Console.ReadLine().Length; + Array.Sort(l); + int p1 = Array.IndexOf(l, lp); + int p2 = Array.LastIndexOf(l, lp); + Console.Write("{0} {1}", p1 / a[1] * 5 + p1 + 1, p2 / a[1] * 5 + p2 + 1); + } + } +} diff --git a/cs/75A.cs b/cs/75A.cs new file mode 100644 index 0000000..1962c07 --- /dev/null +++ b/cs/75A.cs @@ -0,0 +1,25 @@ +using System; + +namespace _75A +{ + class Program + { + static void Main(string[] args) + { + int a = int.Parse(Console.ReadLine()); + int b = int.Parse(Console.ReadLine()); + int c = a + b; + a = int.Parse(a.ToString().Replace("0", "")); + b = int.Parse(b.ToString().Replace("0", "")); + c = int.Parse(c.ToString().Replace("0", "")); + if (a + b == c) + { + Console.WriteLine("YES"); + } + else + { + Console.WriteLine("NO"); + } + } + } +} diff --git a/cs/787A.cs b/cs/787A.cs new file mode 100644 index 0000000..b49d4a1 --- /dev/null +++ b/cs/787A.cs @@ -0,0 +1,43 @@ +using System; + +namespace _787A +{ + class Program + { + static void Main(string[] args) + { + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int[] b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + if ((a[1] - b[1]) % GCD(a[0], b[0]) == 0) + { + while (a[1] != b[1]) + { + if (a[1] < b[1]) + { + a[1] += a[0]; + } + else + { + b[1] += b[0]; + } + } + Console.WriteLine(a[1]); + } + else + { + Console.WriteLine(-1); + } + } + static int GCD(int a, int b) + { + int t; + while (b != 0) + { + t = a % b; + a = b; + b = t; + } + return a; + } + } +} diff --git a/cs/879B.cs b/cs/879B.cs new file mode 100644 index 0000000..47a50ab --- /dev/null +++ b/cs/879B.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _879B +{ + class Program + { + static void Main(string[] args) + { + long[] ip = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + if (ip[0] <= ip[1]) + { + Console.Write("{0}", a.Max()); + } + else + { + int c = 0; + int t = a[0]; + for (int i = 1; i < ip[0]; i++) + { + if (c == ip[1]) + { + break; + } + if (t > a[i]) + { + c++; + } + else + { + c = 1; + t = a[i]; + } + } + Console.Write(t); + } + } + } +} diff --git a/cs/961A.cs b/cs/961A.cs new file mode 100644 index 0000000..e7cc872 --- /dev/null +++ b/cs/961A.cs @@ -0,0 +1,21 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +namespace problem_961A +{ + class problem_961A + { + static void Main(string[] args) + { + int[] ip1 = Console.ReadLine().Split().Select(int.Parse).ToArray(); + int[] ip2 = Console.ReadLine().Split().Select(int.Parse).ToArray(); + int[] a = new int[ip1[0]]; + for (int i = 0; i < ip1[1]; i++) + { + a[ip2[i] - 1]++; + } + Console.Write("{0}", a.Min()); + } + } +} \ No newline at end of file diff --git a/cs/96A.cs b/cs/96A.cs new file mode 100644 index 0000000..41b38d4 --- /dev/null +++ b/cs/96A.cs @@ -0,0 +1,20 @@ +using System; + +namespace problem_96A +{ + public class problem_96A + { + public static void Main(string[] args) + { + string s = Console.ReadLine(); + if (s.Contains("0000000") || s.Contains("1111111")) + { + Console.Write("YES"); + } + else + { + Console.Write("NO"); + } + } + } +} diff --git a/cs/993E.cs b/cs/993E.cs new file mode 100644 index 0000000..baff6b9 --- /dev/null +++ b/cs/993E.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace problem_993E +{ + class problem_993E + { + public static void Main(string[] args) + { + const double pi = 3.14159265359; + const int N = 800005; + int n, m, x, l, L = 0; + int[] s = new int[N]; + int[] R = new int[N]; + int[] c = new int[N]; + C[] a = new C[N]; + C[] b = new C[N]; + int[] ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + n = ip[0]; + x = ip[1]; + c[0]++; + ip = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + for (int i = 1; i <= n; i++) + { + s[i] = s[i - 1] + Convert.ToInt32(ip[i - 1] < x); + c[s[i]]++; + } + for (int i = 0; i <= n; i++) + { + a[i].r = c[i]; + b[i].r = c[n - i]; + } + m = (n << 1); + for (l = 1; l <= m; l <<= 1) + { + L++; + } + for (int i = 0; i < l; i++) + { + R[i] = (R[i >> 1] >> 1| ((i & 1) << (L - 1))); + } + F(a, 1, l, R, pi); + F(b, 1, l, R, pi); + for (int i = 0; i < l; i++) + { + a[i] *= b[i]; + } + F(a, -1, l, R, pi); + Console.Write("{0}", (long)(a[n].r / l + 0.5 - n) >> 1); + for (int i = 1; i <= n; i++) + { + Console.Write(" {0}", (long)(a[i + n].r / l + 0.5)); + } + } + public static void F(C[] A, int o, int l, int[] R, double pi) + { + for (int i = 0; i < l; i++) + { + if (i < R[i]) + { + S(A, i, R[i]); + } + } + for (int i = 1; i < l; i <<= 1) + { + C x, y, wn = new C(Math.Cos(pi / i), Math.Sin(pi * o / i)); + for (int j = 0; j < l; j += (i << 1)) + { + C w = new C(1, 0); + for (int k = 0; k < i; k++, w *= wn) + { + x = A[j + k]; + y = w * A[j + k + i]; + A[j + k] = x + y; + A[j + k + i] = x - y; + } + } + } + + } + public static void S(C[] A, int p1, int p2) + { + C t = A[p1]; + A[p1] = A[p2]; + A[p2] = t; + } + } + public struct C + { + public double r; + public double i; + public C(double r, double i) + { + this.r = r; + this.i = i; + } + public static C operator + (C l, C r) + { + return new C(l.r + r.r, l.i + r.i); + } + public static C operator - (C l, C r) + { + return new C(l.r - r.r, l.i - r.i); + } + public static C operator * (C l, C r) + { + return new C(l.r * r.r - l.i * r.i, l.r * r.i + l.i * r.r); + } + } +} diff --git a/cs/996A.cs b/cs/996A.cs new file mode 100644 index 0000000..44b4490 --- /dev/null +++ b/cs/996A.cs @@ -0,0 +1,22 @@ +using System; + +namespace problem_996A +{ + class problem_996A + { + static void Main(string[] args) + { + int n = int.Parse(Console.ReadLine()); + int[] a = { 1, 5, 10, 20, 100 }; + int i = 4; + int s = 0; + while (n > 0 && i >= 0) + { + s += n / a[i]; + n %= a[i]; + i--; + } + Console.Write(s); + } + } +} \ No newline at end of file diff --git a/cs/996B.cs b/cs/996B.cs new file mode 100644 index 0000000..68d637e --- /dev/null +++ b/cs/996B.cs @@ -0,0 +1,32 @@ +using System; + +namespace problem_996B +{ + class problem_996B + { + public static void Main(string[] args) + { + int n = int.Parse(Console.ReadLine()); + int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + int m = a[0]; + for (int i = 1; i < n; i++) + { + if (a[i] < m) + { + m = a[i]; + } + } + int p = m % n; + while (a[p] > m) + { + m++; + p++; + if (p == n) + { + p = 0; + } + } + Console.Write("{0}", p + 1); + } + } +} diff --git a/cs/999A.cs b/cs/999A.cs new file mode 100644 index 0000000..89989d5 --- /dev/null +++ b/cs/999A.cs @@ -0,0 +1,37 @@ +using System; + +namespace problem_999A +{ + class problem_999A + { + static void Main(string[] args) + { + string[] input = Console.ReadLine().Split(' '); + int n = Convert.ToInt32(input[0]); + int k = Convert.ToInt32(input[1]); + input = Console.ReadLine().Split(' '); + int[] a = new int[n]; + int i; + for (i = 0; i < n; i++) + { + a[i] = Convert.ToInt32(input[i]); + } + i = 0; + int l = 0; + while (i < n && a[i] <= k) + { + l++; + i++; + } + i = n - 1; + int r = 0; + while (i >= 0 && a[i] <= k) + { + r++; + i--; + } + int ouput = Math.Min(l + r, n); + Console.WriteLine(ouput); + } + } +} \ No newline at end of file diff --git a/cs/999B.cs b/cs/999B.cs new file mode 100644 index 0000000..a8f63ae --- /dev/null +++ b/cs/999B.cs @@ -0,0 +1,31 @@ +using System; + +namespace problem_999B +{ + class problem_999B + { + static void Main(string[] args) + { + int n = int.Parse(Console.ReadLine()); + string s = Console.ReadLine(); + for (int i = 1; i <= n; i++) + { + if (n%i == 0) + { + s = Reverse(s.Substring(0, i)) + s.Substring(i); + } + } + Console.Write(s); + } + public static string Reverse(string s) + { + char[] a = s.ToCharArray(); + char[] b = new char[s.Length]; + for (int i = 0; i < s.Length; i++) + { + b[i] = a[s.Length - 1 - i]; + } + return new string(b); + } + } +} diff --git a/java/118A.java b/java/118A.java new file mode 100644 index 0000000..fb2b644 --- /dev/null +++ b/java/118A.java @@ -0,0 +1,24 @@ +package com.company; + +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + // write your code here + Scanner sc = new Scanner(System.in); + String s = sc.next(); + s = s.toLowerCase(); + s = s.replaceAll("a", ""); + s = s.replaceAll("e", ""); + s = s.replaceAll("i", ""); + s = s.replaceAll("o", ""); + s = s.replaceAll("u", ""); + s = s.replaceAll("y", ""); + for (int i = 0; i < s.length(); i++) + { + System.out.print('.'); + System.out.print(s.charAt(i)); + } + } +} diff --git a/java/1A.java b/java/1A.java new file mode 100644 index 0000000..66427d4 --- /dev/null +++ b/java/1A.java @@ -0,0 +1,24 @@ +package com.company; + +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + long n = sc.nextInt(); + long m = sc.nextInt(); + long a = sc.nextInt(); + long r = n / a, c = m / a; + if (n % a != 0) + { + r++; + } + if (m % a != 0) + { + c++; + } + long s = r * c; + System.out.println(s); + } +} \ No newline at end of file diff --git a/java/4A.java b/java/4A.java new file mode 100644 index 0000000..f59e28d --- /dev/null +++ b/java/4A.java @@ -0,0 +1,19 @@ +package com.company; + +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int w = sc.nextInt(); + if (w > 2 && w % 2 == 0) + { + System.out.println("YES"); + } + else + { + System.out.println("NO"); + } + } +} diff --git a/java/50A.java b/java/50A.java new file mode 100644 index 0000000..f12dafc --- /dev/null +++ b/java/50A.java @@ -0,0 +1,15 @@ +package com.company; + +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + // write your code here + Scanner sc = new Scanner(System.in); + int m = sc.nextInt(); + int n = sc.nextInt(); + int out = m*n/2; + System.out.print(out); + } +} diff --git a/py/977A.py b/py/977A.py new file mode 100644 index 0000000..fe33d28 --- /dev/null +++ b/py/977A.py @@ -0,0 +1,10 @@ +n, k = input().split() +n, k = int(n), int(k) +while (k): + if n % 10 == 0: + n /= 10 + else: + n -= 1 + k -= 1 +n = int(n) +print(n) \ No newline at end of file