#include
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
string num = to_string(a + b);
string ans = "";
for (int i = num.size() - 1, j = 0; i >= 0; i -- )
{
ans = num[i] + ans;
++ j;
if (j % 3 == 0 && i && num[i - 1] != '-') ans = "," + ans;
}
cout << ans;
return 0;
}
#include
using namespace std;
string word[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main()
{
string n;
cin >> n;
int s = 0;
for (auto c : n) s += c - '0';
string str = to_string(s);
cout << word[str[0] - '0'];
for (int i = 1; i < str.size(); i ++ ) cout << ' ' << word[str[i] - '0'];
return 0;
}
#include
using namespace std;
int main()
{
string open_id, open_time;
string close_id, close_time;
int m;
cin >> m;
for (int i = 0; i < m; i ++ )
{
string id, in_time, out_time;
cin >> id >> in_time >> out_time;
// 更新
if (!i || in_time < open_time)
{
open_id = id;
open_time = in_time;
}
if (!i || out_time > close_time)
{
close_id = id;
close_time = out_time;
}
}
cout << open_id << ' ' << close_id;
return 0;
}
#include
using namespace std;
const int N = 1010;
string name[N], pwd[N];
string change(string str)
{
string res;
for (auto c : str)
if (c == '1') res += '@';
else if (c == '0') res += '%';
else if (c == 'l') res += 'L';
else if (c == 'O') res += 'o';
else res += c;
return res;
}
int main()
{
int n;
cin >> n;
int m = 0;
for (int i = 0; i < n; i ++ )
{
string a, b;
cin >> a >> b;
string c = change(b);
if (b != c) name[m] = a, pwd[m ++ ] = c;
}
if (!m)
{
if (n == 1) puts("There is 1 account and no account is modified");
else printf("There are %d accounts and no account is modified", n);
}
else
{
cout << m << endl;
for (int i = 0; i < m; i ++ ) cout << name[i] << ' ' << pwd[i] << endl;
}
return 0;
}
#include
#include
using namespace std;
int main()
{
string s1, s2;
getline(cin, s1);
getline(cin, s2);
unordered_set<char> hash;
for (auto c : s2) hash.insert(c);
string res;
for (auto c : s1)
if (!hash.count(c))
res += c;
cout << res;
return 0;
}
#include
using namespace std;
int main()
{
string a, b, c, d;
cin >> a >> b >> c >> d;
int k = 0;
while (true)
{
if (a[k] == b[k] && 'A' <= a[k] && 'G' >= a[k]) break;
k ++ ;
}
char weekdays[7][4] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
printf("%s ", weekdays[a[k] - 'A']);
k ++ ;
while (true)
{
if (a[k] == b[k] && (a[k] >= '0' && a[k] <= '9' || a[k] >= 'A' && a[k] <= 'N')) break;
k ++ ;
}
printf("%02d:", a[k] <= '9' ? a[k] - '0' : a[k] - 'A' + 10);
for (int i = 0;; i ++ )
if (c[i] == d[i] && (c[i] >= 'a' && c[i] <= 'z' || c[i] >= 'A' && c[i] <= 'Z'))
{
printf("%02d", i);
break;
}
return 0;
}
#include
using namespace std;
int main()
{
string s;
cin >> s;
if (s[0] == '-') cout << '-';
int k = s.find('E');
string a = s[1] + s.substr(3, k - 3);
int b = stoi(s.substr(k + 1));
if (b <= 0) cout << "0." << string(- b - 1, '0');
else if (b < a.size() - 1) a = a.substr(0, b + 1) + '.' + a.substr(b + 1);
else a += string(b - a.size() + 1, '0');
cout << a;
return 0;
}
#include
using namespace std;
const int N = 110;
string s[N];
int main()
{
int n;
cin >> n;
getchar();
for (int i = 0; i < n; i ++ ) getline(cin, s[i]);
for (int k = s[0].size(); k; k -- )
{
string sf = s[0].substr(s[0].size() - k);
bool is_matched = true;
for (int i = 1; i < n; i ++ )
if (s[i].size() < k || s[i].substr(s[i].size() - k) != sf)
{
is_matched = false;
break;
}
if (is_matched)
{
cout << sf;
return 0;
}
}
cout << "nai";
return 0;
}
#include
using namespace std;
int main()
{
string a, b;
cin >> a >> b;
bool st[200] = {0};
b += '#';
for (int i = 0, j = 0; i < a.size(); i ++ )
{
char x = toupper(a[i]), y = toupper(b[j]);
if (x == y) j ++ ;
else
{
if (!st[x]) st[x] = true, cout << x;
}
}
return 0;
}
#include
using namespace std;
int main()
{
int n;
cin >> n;
double sum = 0;
int cnt = 0;
while (n -- )
{
string num;
cin >> num;
double x;
bool success = true;
try
{
size_t idx;
x = stof(num, &idx);
if (idx < num.size()) success = false;
}
catch(...)
{
success = false;
}
if (x < -1000 || x > 1000) success = false;
int k = num.find('.');
if (k != -1 && num.size() - k > 3) success = false;
if (success) cnt ++ , sum += x;
else printf("ERROR: %s is not a legal number\n", num.c_str());
}
if (cnt > 1) printf("The average of %d numbers is %.2lf", cnt, sum / cnt);
else if (cnt == 1) printf("The average of 1 number is %.2lf", sum);
else printf("The average of 0 numbers is Undefined");
return 0;
}
#include
#include
using namespace std;
const int N = 1e3 + 10;
string name[N];
int main()
{
int m, n, s;
cin >> m >> n >> s;
unordered_set<string> se;
for (int i = 1; i <= m; i ++ ) cin >> name[i];
int k = s;
while (k <= m)
{
if (se.find(name[k]) != se.end()) k ++ ;
else
{
cout << name[k] << endl;
se.insert(name[k]);
k += n;
}
}
if (se.empty()) cout << "Keep going...";
return 0;
}
#include
using namespace std;
const int N = 1010;
double a[N], b[N], c[N];
int main()
{
int k;
cin >> k;
while (k -- )
{
int ex;
double co;
cin >> ex >> co;
a[ex] = co;
}
cin >> k;
while (k -- )
{
int ex;
double co;
cin >> ex >> co;
b[ex] = co;
}
for (int i = 0; i < N; i ++ ) c[i] = a[i] + b[i];
k = 0;
for (int i = 0; i < N; i ++ )
if (c[i])
k ++ ;
cout << k;
for (int i = N - 1; i >= 0; i -- )
if (c[i])
printf(" %d %.1lf", i, c[i]);
return 0;
}
#include
using namespace std;
const int N = 1010, M = N * 2;
double a[N], b[N], c[M];
void input(double a[])
{
int k;
cin >> k;
while (k -- )
{
int n;
double v;
cin >> n >> v;
a[n] = v;
}
}
int main()
{
input(a);
input(b);
for (int i = 0; i < N; i ++ )
for (int j = 0; j < N; j ++ )
c[i + j] += a[i] * b[j];
int k = 0;
for (int i = 0; i < M; i ++ )
if (c[i])
k ++ ;
cout << k;
for (int i = M - 1; i >= 0; i -- )
if (c[i])
printf(" %d %.1lf", i, c[i]);
return 0;
}
#include
#include
#include
using namespace std;
int main()
{
string A;
vector<int> a;
cin >> A;
for (int i = A.size() - 1; i >= 0; i -- ) a.push_back(A[i] - '0');
vector<int> b;
int t = 0;
for (int i = 0; i < a.size(); i ++ )
{
int s = a[i] + a[i] + t;
b.push_back(s % 10);
t = s / 10;
}
if (t) b.push_back(1);
vector<int> c = b;
sort(c.begin(), c.end());
sort(a.begin(), a.end());
if (a == c) puts("Yes");
else puts("No");
for (int i = b.size() - 1; i >= 0; i -- ) cout << b[i];
return 0;
}
思路 :实则就是进位制的操作,不用if特判
语法 :scanf和printf的妙用
#include
using namespace std;
int main()
{
int a, b, c, d, e, f;
scanf("%d.%d.%d %d.%d.%d", &a, &b, &c, &d, &e, &f);
a += d, b += e, c += f;
b += c / 29, c %= 29;
a += b / 17, b %= 17;
printf("%d.%d.%d", a, b, c);
return 0;
}
#include
#include
using namespace std;
bool check(vector<int> A)
{
for (int i = 0, j = A.size() - 1; i < j; i ++ , j -- )
if (A[i] != A[j])
return false;
return true;
}
void print(vector<int> A)
{
for (int i = A.size() - 1; i >= 0; i -- )
cout << A[i];
}
vector<int> add(vector<int> A, vector<int> B)
{
vector<int> C;
for (int i = 0, t = 0; i < A.size() || i < B.size() || t; i ++ )
{
if (i < A.size()) t += A[i];
if (i < B.size()) t += B[i];
C.push_back(t % 10);
t /= 10;
}
return C;
}
int main()
{
string a;
cin >> a;
vector<int> A;
for (int i = 0; i < a.size(); i ++ ) A.push_back(a[a.size() - 1 - i] - '0');
for (int i = 0; i < 10; i ++ )
{
if (check(A)) break;
vector<int> B(A.rbegin(), A.rend());
print(A), cout << " + ", print(B), cout << " = ";
A = add(A, B);
print(A), cout << endl;
}
if (check(A)) print(A), cout << " is a palindromic number.";
else cout << "Not found in 10 iterations.";
return 0;
}
#include
#include
using namespace std;
typedef long long ll;
int get(char c)
{
if (c <= '9') return c - '0';
return c - 'a' + 10;
}
ll calc(string n, ll r)
{
ll res = 0;
for (auto c : n)
{
if ((double)res * r + get(c) > 1e16) return 1e18;
res = res * r + get(c);
}
return res;
}
int main()
{
string n1, n2;
cin >> n1 >> n2;
int tag, radix;
cin >> tag >> radix;
if (tag == 2) swap(n1, n2);
ll target = calc(n1, radix);
ll l = 0, r = target + 1;
// ll l = 0, r = max(target, 36ll);
for (auto c : n2) l = max(l, (ll)get(c) + 1);
while (l < r)
{
ll mid = l + r >> 1;
if (calc(n2, mid) >= target) r = mid; // == problem!
else l = mid + 1;
}
if (calc(n2, r) == target) cout << r;
else cout << "Impossible";
return 0;
}
#include
using namespace std;
typedef long long LL;
bool is_prime(int n)
{
if (n == 1) return false;
for (int i = 2; i * i <= n; i ++ )
if (n % i == 0)
return false;
return true;
}
bool check(int n, int d)
{
if (!is_prime(n)) return false;
LL r = 0;
while (n)
{
r = r * d + n % d;
n /= d;
}
return is_prime(r);
}
int main()
{
int n, d;
while (cin >> n >> d, n >= 1)
{
if (check(n, d)) puts("Yes");
else puts("No");
}
return 0;
}
#include
#include
using namespace std;
vector<int> nums;
bool check()
{
for (int i = 0, j = nums.size() - 1; i < j; i ++ , j -- )
if (nums[i] != nums[j])
return false;
return true;
}
int main()
{
int n, b;
cin >> n >> b;
if (!n) nums.push_back(0);
while (n) nums.push_back(n % b), n /= b;
if (check()) puts("Yes");
else puts("No");
cout << nums.back();
for (int i = nums.size() - 2; i >= 0; i -- ) cout << ' ' << nums[i];
return 0;
}
#include
using namespace std;
int a[3];
char get(int x)
{
if (x > 9) return 'A' + x - 10;
return '0' + x;
}
int main()
{
for (int i = 0; i < 3; i ++ ) cin >> a[i];
cout << '#';
for (int i = 0; i < 3; i ++ ) cout << get(a[i] / 13) << get(a[i] % 13);
return 0;
}
#include
#include
using namespace std;
char names[][5] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int get(string word)
{
for (int i = 0; i < 25; i ++ )
if (names[i] == word)
{
if (i < 13) return i;
return 13 * (i - 12);
}
return -1; // 一定不会执行
}
int main()
{
int T;
cin >> T;
getchar();
while (T -- )
{
string line;
getline(cin, line);
stringstream ssin(line);
if (line[0] <= '9')
{
int v;
ssin >> v;
if (v < 13) cout << names[v] << endl;
else
{
cout << names[12 + v / 13];
if (v % 13 != 0) cout << " " << names[v % 13];
cout << endl;
}
}
else
{
string word;
int res = 0;
while (ssin >> word) res += get(word);
cout << res << endl;
}
}
}
#include
#include
#include
#include
#include
using namespace std;
unordered_map<string, vector<int>> grades;
vector<int> q[4]; // A C M E
int get_grade(vector<int> &a, int x)
{
int l = 0, r = a.size() - 1;
while (l < r)
{
int mid = (l + r + 1) >> 1;
if (a[mid] <= x) l = mid;
else r = mid - 1;
}
return a.size() - r;
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i ++ )
{
string id;
cin >> id;
int t[4] = {0};
for (int j = 1; j < 4; j ++ )
{
cin >> t[j];
t[0] += t[j];
}
t[0] = round(t[0] / 3.0);
for (int j = 0; j < 4; j ++ )
{
grades[id].push_back(t[j]);
q[j].push_back(t[j]);
}
}
for (int i = 0; i < 4; i ++ ) sort(q[i].begin(), q[i].end());
char names[] = "ACME";
while (m -- )
{
string id;
cin >> id;
if (grades.count(id) == 0) puts("N/A");
else
{
int res = n + 1;
char c;
for (int i = 0; i < 4; i ++ )
{
int rank = get_grade(q[i], grades[id][i]);
// int rank = 1 + n - (upper_bound(q[i].begin(), q[i].end(), grades[id][i]) - q[i].begin()); // 在vector要逆序的情况下
if (res > rank)
{
res = rank;
c = names[i];
}
}
cout << res << ' ' << c << endl;
}
}
}
#include
#include
using namespace std;
const int N = 510;
int n, m, S, T;
int w[N], g[N][N];
int cnt[N], sum[N];
int dist[N];
bool st[N];
void dijkstra()
{
memset(dist, 0x3f, sizeof dist); // 初始化
dist[S] = 0, cnt[S] = 1, sum[S] = w[S];
for (int i = 0; i < n - 1; i ++ )
{
int t = -1;
for (int j = 0; j < n; j ++ )
if (!st[j] && (t == -1 || dist[t] > dist[j]))
t = j;
st[t] = true; // 标记
for (int j = 0; j < n; j ++ )
if (dist[j] > dist[t] + g[t][j])
{
dist[j] = dist[t] + g[t][j];
cnt[j] = cnt[t];
sum[j] = sum[t] + w[j];
}
else if (dist[j] == dist[t] + g[t][j])
{
cnt[j] += cnt[t];
sum[j] = max(sum[j], sum[t] + w[j]);
}
}
}
int main()
{
cin >> n >> m >> S >> T;
for (int i = 0; i < n; i ++ ) cin >> w[i];
memset(g, 0x3f, sizeof g); // 初始化
while (m -- )
{
int a, b, c;
cin >> a >> b >> c;
g[a][b] = g[b][a] = min(g[a][b], c); // 无向图
}
dijkstra();
cout << cnt[T] << ' ' << sum[T];
return 0;
}
// 堆优化版
#include
#include
#include
using namespace std;
const int N = 510, M = N * N; // 注意M大小
typedef pair<int, int> pii;
int h[N], w[M], e[M], ne[M], idx;
int wt[N];
int dist[N];
bool st[N];
int cnt[N], sum[N];
int n, m, S, T;
void add(int a, int b, int c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}
void dijkstra()
{
memset(dist, 0x3f, sizeof dist);
dist[S] = 0;
cnt[S] = 1, sum[S] = wt[S];
priority_queue<pii, vector<pii>, greater<pii>> heap;
heap.push({0, S});
// st[S] = true; 注意!!!
while (heap.size())
{
auto t = heap.top();
heap.pop();
int ver = t.second, distance = t.first;
if (st[ver]) continue;
st[ver] = true;
for (int i = h[ver]; i != -1; i = ne[i])
{
int j = e[i];
if (dist[j] > dist[ver] + w[i])
{
dist[j] = dist[ver] + w[i];
cnt[j] = cnt[ver];
sum[j] = sum[ver] + wt[j];
heap.push({dist[j], j}); // 被更新松弛了的点要放入优先队列内
}
else if (dist[j] == dist[ver] + w[i])
{
cnt[j] += cnt[ver];
sum[j] = max(sum[j], sum[ver] + wt[j]);
}
}
}
}
int main()
{
memset(h, -1, sizeof h);
cin >> n >> m >> S >> T;
for (int i = 0; i < n; i ++ ) cin >> wt[i];
while (m -- )
{
int a, b, c;
cin >> a >> b >> c;
add(a, b, c);
add(b, a, c);
}
dijkstra();
cout << cnt[T] << ' ' << sum[T];
return 0;
}
#include
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b)
{
return b ? gcd(b, a % b) : a;
}
int main()
{
int n;
cin >> n;
LL a = 0, b = 1;
for (int i = 0; i < n; i ++ )
{
LL c, d;
scanf("%lld/%lld", &c, &d);
LL t = gcd(c, d);
c /= t, d /= t;
t = gcd(b, d);
a = d / t * a + b / t * c;
b = b / t * d;
t = gcd(a, b);
a /= t, b /= t;
}
if (b == 1) cout << a;
else
{
if (a > b) printf("%lld ", a / b), a %= b;
printf("%lld/%lld", a, b);
}
return 0;
}
#include
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b)
{
return b ? gcd(b, a % b) : a;
}
void print(LL a, LL b)
{
LL t = gcd(a, b);
a /= t, b /= t;
if (b < 0) a *= -1, b *= -1;
bool is_minus = a < 0;
if (is_minus) cout << "(";
if (b == 1) cout << a;
else
{
if (abs(a) > b) printf("%lld ", a / b), a = abs(a) % b;
printf("%lld/%lld", a , b);
}
if (is_minus) cout << ")";
}
void add(LL a, LL b, LL c, LL d)
{
print(a, b), cout << " + ", print(c, d), cout << " = ";
a = a * d + b * c;
b = b * d;
print(a, b), cout << endl;
}
void sub(LL a, LL b, LL c, LL d)
{
print(a, b), cout << " - ", print(c, d), cout << " = ";
a = a * d - b * c;
b = b * d;
print(a, b), cout << endl;
}
void mul(LL a, LL b, LL c, LL d)
{
print(a, b), cout << " * ", print(c, d), cout << " = ";
a = a * c;
b = b * d;
print(a, b), cout << endl;
}
void div(LL a, LL b, LL c, LL d)
{
print(a, b), cout << " / ", print(c, d), cout << " = ";
if (!c) puts("Inf");
else
{
a = a * d;
b = b * c;
print(a, b), cout << endl;
}
}
int main()
{
LL a, b, c, d;
scanf("%lld/%lld %lld/%lld", &a, &b, &c, &d);
add(a, b, c, d);
sub(a, b, c, d);
mul(a, b, c, d);
div(a, b, c, d);
return 0;
}
#include
#include
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> res;
for (int i = 2; i * i <= n; i ++ )
if (n % i == 0)
{
vector<int> seq;
for (int m = n, j = i; m % j == 0; j ++ )
{
seq.push_back(j);
m /= j;
}
if (seq.size() > res.size()) res = seq;
}
if (res.empty()) res.push_back(n);
cout << res.size() << endl;
cout << res[0];
for (int i = 1; i < res.size(); i ++ ) cout << "*" << res[i];
return 0;
}
#include
using namespace std;
int main()
{
int n;
cin >> n;
long double res = 0;
for (int i = 1; i <= n; i ++ )
{
long double x;
cin >> x;
res += x * i * (n - i + 1);
}
printf("%.2Lf", res);
return 0;
}
#include
using namespace std;
typedef long long ll;
int main()
{
int n;
cin >> n;
ll res = 0;
for (int i = 1; i <= n; i ++ )
{
double x;
cin >> x;
res += (ll)(1000 * x) * i * (n - i + 1); // 乘1000放大数字,避免精度的影响,注意括号
}
printf("%.2lf", res / 1000.0); // 加上.0可以转化成小数
return 0;
}
#include
using namespace std;
const int N = 200;
int st[N]; // 1没坏,0坏了,2输出过
int main()
{
string s;
int k;
cin >> k >> s;
for (int i = 0; i < s.size(); i ++ )
{
int j = i + 1;
while (j < s.size() && s[j] == s[i]) j ++ ;
int len = j - 1 - i + 1;
if (len % k) st[s[i]] = 1;
i = j - 1; // 因为还要 ++
}
string res;
for (int i = 0; i < s.size(); i ++ )
{
if (!st[s[i]]) cout << s[i], st[s[i]] = 2;
if (st[s[i]] == 1) res += s[i];
else
{
res += s[i];
i += k - 1;
}
}
cout << endl << res << endl;
return 0;
}
#include
using namespace std;
const int N = 1e4 + 10;
int Rank[N], st[N];
void init()
{
for (int i = 2; i < N; i ++ )
if (!st[i])
{
st[i] = 1;
for (int j = i * 2; j < N; j += i)
st[j] = 2;
}
}
int main()
{
init();
int n;
cin >> n;
for (int i = 1; i <= n; i ++ )
{
int id;
cin >> id;
Rank[id] = i;
}
int k;
cin >> k;
while (k -- )
{
int id;
cin >> id;
printf("%04d: ", id);
if (!Rank[id]) puts("Are you kidding?");
else if (Rank[id] == -1) puts("Checked");
else
{
int t = st[Rank[id]];
if (!t) puts("Mystery Award");
else if (t == 1) puts("Minion");
else puts("Chocolate");
Rank[id] = -1;
}
}
return 0;
}
#include
using namespace std;
const int N = 4e4;
int primes[N], cnt;
bool st[N];
void init()
{
for (int i = 2; i < N; i ++ )
if (!st[i])
{
primes[cnt ++ ] = i;
for (int j = i * 2; j < N; j += i)
st[j] = true;
}
}
bool check(string s)
{
int x = stoi(s);
for (int i = 0; primes[i] <= x / primes[i]; i ++ )
if (x % primes[i] == 0)
return false;
return true;
}
int main()
{
init();
int l, k;
string s;
cin >> l >> k >> s;
for (int i = 0; i + k <= l; i ++ )
{
string ss = s.substr(i, k);
if (check(ss))
{
cout << ss;
return 0;
}
}
cout << 404;
return 0;
}
#include
using namespace std;
const int N = 1e4 + 10;
int num[N];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ ) cin >> num[i];
int res = -1e9, sum = 0, from = 0, to = 0, f = 0;
for (int i = 0; i < n; i ++ )
{
sum += num[i];
if (sum > res) res = sum, from = f, to = i;
if (sum < 0) sum = 0, f = i + 1;
}
if (res < 0) res = 0, from = 0, to = n - 1;
cout << res << ' ' << num[from] << ' ' << num[to];
return 0;
}
#include
using namespace std;
const int N = 1e4 + 10;
int w[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> w[i];
int res = -1, l, r;
for (int i = 1, sum = -1, start; i <= n; i ++ )
{
if (sum < 0) sum = 0, start = i;
sum += w[i];
if (sum > res)
{
res = sum;
l = w[start], r = w[i];
}
}
if (res < 0) res = 0, l = w[1], r = w[n];
cout << res << ' ' << l << ' ' << r;
return 0;
}
#include
#include
using namespace std;
int main()
{
int n;
cin >> n;
set<int> se;
while (n -- )
{
int x;
cin >> x;
int s = 0;
while (x) s += x % 10, x /= 10;
se.insert(s);
}
cout << se.size() << endl;;
bool is_first = true;
for (auto x : se)
{
if (is_first) is_first = false;
else cout << ' ';
cout << x;
}
return 0;
}
#include
#include
using namespace std;
int main()
{
int n;
cin >> n;
unordered_set<int> se;
while (n -- )
{
int x;
cin >> x;
se.insert(x);
}
int res = 1;
while (se.count(res)) res ++ ;
cout << res;
return 0;
}
#include
using namespace std;
int main()
{
int n;
cin >> n;
int res = 0, last = 0;
while (n -- )
{
int cur;
cin >> cur;
if (cur > last) res += 6 * (cur - last);
else res += 4 * (last - cur);
res += 5;
last = cur;
}
cout << res;
return 0;
}
#include
using namespace std;
int main()
{
double res = 1;
double w, t, l;
for (int i = 0; i < 3; i ++ )
{
cin >> w >> t >> l;
double x = max(w, max(t, l));
if (w == x) cout << "W ";
else if (t == x) cout << "T ";
else cout << "L ";
res *= x;
}
printf("%.2lf", (res * 0.65 - 1) * 2);
return 0;
}
#include
using namespace std;
char g[85][85];
int main()
{
string str;
cin >> str;
int n = str.size();
int n1 = (n + 2) / 3;
int n3 = n1, n2 = n - n1 - n3 + 2;
int k = 0;
for (int i = 0; i < n1; i ++ ) g[i][0] = str[k ++ ];
for (int i = 1; i <= n2 - 2; i ++ ) g[n1 - 1][i] = str[k ++ ];
for (int i = n1 - 1; i >= 0; i -- ) g[i][n2 - 1] = str[k ++ ];
for (int i = 0; i < n1; i ++ )
{
for (int j = 0; j < n2; j ++ )
if (g[i][j]) cout << g[i][j];
else cout << ' ';
cout << endl;
}
return 0;
}
#include
using namespace std;
const int N = 1e5 + 10;
int a[N], c[N];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ )
{
cin >> a[i];
c[a[i]] ++ ;
}
for (int i = 0; i < n; i ++ )
if (c[a[i]] == 1)
{
cout << a[i];
return 0;
}
puts("None");
return 0;
}
#include
#include
using namespace std;
const int N = 60;
int p[N], q[N], w[N];
void print(int x)
{
if (x <= 13) cout << 'S' << x;
else if (x <= 26) cout << 'H' << x - 13;
else if (x <= 39) cout << 'C' << x - 26;
else if (x <= 52) cout << 'D' << x - 39;
else cout << 'J' << x - 52;
}
int main()
{
int k;
cin >> k;
for (int i = 1; i <= 54; i ++ ) cin >> q[i];
for (int i = 1; i <= 54; i ++ ) p[i] = i;
while (k -- )
{
memcpy(w, p, sizeof p);
for (int i = 1; i <= 54; i ++ ) p[q[i]] = w[i];
}
for (int i = 1; i <= 54; i ++ )
{
print(p[i]);
if (i != 54) cout << ' ';
}
}
#include
#include
using namespace std;
int main()
{
int n, m;
cin >> m >> n;
unordered_map<int, int> cnt;
for (int i = 0; i < n; i ++ )
for (int j = 0; j < m; j ++ )
{
int x;
cin >> x;
if ( ++ cnt[x] > n * m / 2)
{
cout << x;
break;
}
}
return 0;
}
#include
using namespace std;
typedef long long LL;
bool check(LL a, LL b, LL c)
{
LL d = a + b;
if (a >= 0 && b >= 0 && d < 0) return true;
if (a < 0 && b < 0 && d >= 0) return false;
return a + b > c;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++ )
{
LL a, b, c;
scanf("%lld%lld%lld", &a, &b, &c);
if (check(a, b, c)) printf("Case #%d: true\n", i);
else printf("Case #%d: false\n", i);
}
return 0;
}
#include
#include
#include
using namespace std;
vector<int> get(int n)
{
int nums[4];
for (int i = 0; i < 4; i ++ )
{
nums[i] = n % 10;
n /= 10;
}
sort(nums, nums + 4);
int a = 0;
for (int i = 0; i < 4; i ++ ) a = a * 10 + nums[i];
reverse(nums, nums + 4);
int b = 0;
for (int i = 0; i < 4; i ++ ) b = b * 10 + nums[i];
return {b, a};
}
int main()
{
int n;
cin >> n;
do
{
auto t = get(n);
printf("%04d - %04d = %04d\n", t[0], t[1], t[0] - t[1]);
n = t[0] - t[1];
} while (n && n != 6174);
return 0;
}
#include
#include
using namespace std;
int main()
{
string a, b;
cin >> a >> b;
unordered_map<char, int> S;
for (auto c : a) S[c] ++ ;
for (auto c : b) S[c] -- ;
int sp = 0, sn = 0;
for (auto item : S)
if (item.second > 0) sp += item.second;
else sn -= item.second;
if (sn) printf("No %d", sn);
else printf("Yes %d", sp);
return 0;
}
#include
#include
using namespace std;
const int N = 1e3 + 10;
bool row[N], dg[N * 2], udg[N * 2];
int main()
{
int T;
cin >> T;
while (T -- )
{
memset(row, 0, sizeof row);
memset(dg, 0, sizeof dg);
memset(udg, 0, sizeof udg);
int n;
cin >> n;
bool success = true;
for (int y = 1; y <= n; y ++ )
{
int x;
cin >> x;
if (row[x] || dg[y + x] || udg[y - x + n]) success = false;
row[x] = dg[y + x] = udg[y - x + n] = true;
}
if (success) puts("YES");
else puts("NO");
}
return 0;
}
#include
using namespace std;
int main()
{
int T;
cin >> T;
while (T -- )
{
string s;
cin >> s;
int len = s.size() / 2;
int left = stoi(s.substr(0, len));
int right = stoi(s.substr(len, len));
int n = stoi(s);
if (left * right && n % (left * right) == 0) puts("Yes");
else puts("No");
}
return 0;
}
#include
using namespace std;
int main()
{
int d, n;
cin >> d >> n;
string cur = to_string(d);
for (int k = 0; k < n - 1; k ++ )
{
string next;
for (int i = 0; i < cur.size();)
{
int j = i + 1;
while (j < cur.size() && cur[i] == cur[j]) j ++ ;
next += cur[i] + to_string(j - i);
i = j;
}
cur = next;
}
cout << cur;
return 0;
}
#include
using namespace std;
const int N = 1e5 + 10;
int s[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> s[i], s[i] += s[i - 1];
int m;
cin >> m;
while (m -- )
{
int l, r;
cin >> l >> r;
if (r < l) swap(l, r);
cout << min(s[r - 1] - s[l - 1], s[n] - s[r - 1] + s[l - 1]);
if (m != 0) cout << endl;
}
}
#include
using namespace std;
const int N = 110;
int q[N];
int judge(int k, int i, int j) // 1为假话,0为真话
{
int t = q[k];
if (t > 0)
{
if (t == i || t == j)
return 1;
return 0;
}
t = -t;
if (t == i || t == j) return 0;
return 1;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> q[i];
for (int i = 1; i <= n; i ++ )
for (int j = i + 1; j <= n; j ++ )
{
int s = 0;
s = judge(i, i, j) + judge(j, i, j);
if (s != 1) continue;
s = 0;
for (int k = 1; k <= n; k ++ )
s += judge(k, i, j);
if (s != 2) continue;
cout << i << ' ' << j;
return 0;
}
cout << "No Solution";
return 0;
}