forked from abheekd/usaco-practice
Abheek Dhawan
3 years ago
commit
8ccf561c67
14 changed files with 166 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,40 @@ |
|||
using namespace std; |
|||
|
|||
#include <iostream> |
|||
#include <string> |
|||
|
|||
string parseString(string n) { |
|||
string m = n; |
|||
string o = n; |
|||
for (int i = 0; i < n.length(); i++) { |
|||
m[i] = toupper(n[i]); |
|||
} |
|||
o = m; |
|||
o[0] = tolower(m[0]); |
|||
if (m == n) { |
|||
return "v1"; |
|||
} else if (o == n) { |
|||
return "v2"; |
|||
} else { |
|||
return "v3"; |
|||
} |
|||
} |
|||
|
|||
int main() { |
|||
string n; |
|||
cin >> n; |
|||
string w; |
|||
w = parseString(n); |
|||
if (w == "v3") { |
|||
cout << n << endl; |
|||
} else { |
|||
for (int i = 0; i < n.length(); i++) { |
|||
if (i == 0 && w == "v2") { |
|||
n[0] = toupper(n[0]); |
|||
} else { |
|||
n[i] = tolower(n[i]); |
|||
} |
|||
} |
|||
cout << n << endl; |
|||
} |
|||
} |
Binary file not shown.
@ -0,0 +1,30 @@ |
|||
using namespace std; |
|||
|
|||
#include <iostream> |
|||
|
|||
int main() { |
|||
int n, k; |
|||
cin >> n >> k; |
|||
int w; |
|||
int a = 0; |
|||
for (int i = 0; i < n; i++) { |
|||
int j; |
|||
cin >> j; |
|||
if (j == 0) { |
|||
break; |
|||
} |
|||
if (i == k - 1) { |
|||
w = j; |
|||
a++; |
|||
} else if (i > k - 1) { |
|||
if (j == w) { |
|||
a++; |
|||
} else { |
|||
break; |
|||
} |
|||
} else { |
|||
a++; |
|||
} |
|||
} |
|||
cout << a << endl; |
|||
} |
Binary file not shown.
@ -0,0 +1,18 @@ |
|||
using namespace std; |
|||
|
|||
#include <iostream> |
|||
|
|||
int main() { |
|||
int k, n, total_cost; |
|||
total_cost = 0; |
|||
long w; |
|||
cin >> k >> n >> w; |
|||
for (int i = 1; i < w + 1; i++) { |
|||
total_cost += i * k; |
|||
} |
|||
total_cost -= n; |
|||
if (total_cost < 0) { |
|||
total_cost = 0; |
|||
} |
|||
cout << total_cost << endl; |
|||
} |
Binary file not shown.
@ -0,0 +1,21 @@ |
|||
using namespace std; |
|||
|
|||
#include <iostream> |
|||
|
|||
int main() { |
|||
int n; |
|||
int c = 0; |
|||
cin >> n; |
|||
for (int i = 0; i < n; i++) { |
|||
int k = 0; |
|||
for (int j = 0; j < 3; j++) { |
|||
int l; |
|||
cin >> l; |
|||
k += l; |
|||
} |
|||
if (k >= 2) { |
|||
c += 1; |
|||
} |
|||
} |
|||
cout << c << endl; |
|||
} |
Binary file not shown.
@ -0,0 +1,15 @@ |
|||
using namespace std; |
|||
|
|||
#include <iostream> |
|||
|
|||
int main() { |
|||
int n; |
|||
int i; |
|||
cin >> n; |
|||
i = n - 2; |
|||
if (i % 2 == 0 && i > 0) { |
|||
cout << "YES" << endl; |
|||
} else { |
|||
cout << "NO" << endl; |
|||
} |
|||
} |
Binary file not shown.
@ -0,0 +1,21 @@ |
|||
using namespace std; |
|||
|
|||
#include <iostream> |
|||
#include <string.h> |
|||
|
|||
int main() { |
|||
int n; |
|||
cin >> n; |
|||
for (int i = 0; i < n; i++) { |
|||
string s; |
|||
cin >> s; |
|||
int length = s.length(); |
|||
char first = s.front(); |
|||
char last = s.back(); |
|||
if (length > 10) { |
|||
cout << first << length << last << endl; |
|||
} else { |
|||
cout << s << endl; |
|||
} |
|||
} |
|||
} |
Binary file not shown.
@ -0,0 +1,21 @@ |
|||
#include <iostream> |
|||
int a, b, x, y; |
|||
|
|||
int main() { |
|||
std::cin >> a >> b >> x >> y; |
|||
int path1; |
|||
int path2; |
|||
int path3; |
|||
int ans; |
|||
path1 = std::abs(a - b); |
|||
path2 = std::abs(a - x) + std::abs(y - b); |
|||
path3 = std::abs(a - y) + std::abs(x - b); |
|||
ans = path1; |
|||
if (path2 < ans) { |
|||
ans = path2; |
|||
} |
|||
if (path3 < ans) { |
|||
ans = path3; |
|||
} |
|||
std::cout << ans << std::endl; |
|||
} |
Loading…
Reference in new issue