刷題證明
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
int x, y, z;
cin >> t;
while (t--)
{
cin >> x >> y >> z;
int big=max(max(x, y), z);
if (x > max(y, z))
{
cout << "0 ";
}
else if(x<=max(y,z))
{
cout << abs(big - x) +1<< " ";
}
if (y > max(x, z))
{
cout << "0 ";
}
else if(y<=max(x,z))
{
cout << abs(big - y)+1 << " ";
}
if (z > max(x, y))
{
cout << "0 " << endl;
}
else if(z<=max(x,y))
{
cout << abs(big- z)+1 << " " << endl;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n = 0, ans = 0;
cin >> n;
int counter = 1;
while (n > 0)
{
n = n - counter;
ans++;
counter += 2;
}
cout << ans << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
char game[60];
char check[30];
cin >> game;
for (int i = 0; i < strlen(game); i += 2)
{
if (game[i] == 'a')
{
game[i] = 'b';
}
else
{
game[i] = 'a';
}
}
for (int i = 1; i <strlen(game); i += 2)
{
if (game[i] == 'z')
{
game[i] = 'y';
}
else
{
game[i] = 'z';
}
}
printf("%s\n", game);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxx=2e6;
int b[maxx];
signed main()
{
int t, n, k;
cin >> t;
while (t--)
{
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> b[i];
}
sort(b, b + n);
for (int i = n - 2; i >= n -k-1; i--)
{
b[n-1] += b[i];
}
cout << b[n-1] << endl;
}
}
#include<bits/stdc++.h>
using namespace std;
int ans[200100], a[200100];
int main()
{
int t, n;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1; i <= n; i++)
{
ans[i] = 0;
a[i] = 0;
}
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
ans[max(1, i - x+ 1)]++;
ans[i + 1]--;
}
for (int i = 1; i <= n; i++)
{
a[i] = a[i - 1] + ans[i];
printf("%d ", a[i]> 0);
}
cout << endl;
}
#include<bits/stdc++.h>
using namespace std;
bool cmp(const int& x, const int& y)
{
return x > y;
}
int main()
{
int t;
int arr[60];
int sum;
cin >> t;
while (t--)
{
int n;
cin >> n;
sum = 0;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
sum += arr[i];
}
if (sum > 0)
{
printf("YES\n");
sort(arr, arr + n, cmp);
}
else if (sum == 0)
{
printf("NO\n");
continue;
}
else
{
printf("YES\n");
sort(arr, arr + n);
}
for (int i = 0; i < n; i++)
{
cout << arr[i]<<" ";
}
cout << endl;
for (int i = 0; i <= n; i++)
{
arr[i] = 0;
}
}
}
#include<bits/stdc++.h>
using namespace std;
long long arr[30][30];
int main()
{
int m;
long long n[1][1];
cin >> n[0][0];
cin >> m;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < 2; j++)
{
cin >> arr[i][j];
}
}
for (int i = m - 1; i > 0; i--)
{
for (int j = 0; j <=i-1; j++)
{
if (arr[j][1] > arr[j + 1][1])
{
swap(arr[j][1], arr[j + 1][1]);
swap(arr[j][0], arr[j + 1][0]);
}
}
}
if (n[0][0]<= arr[m - 1][0])
{
cout << n[0][0] * arr[m - 1][1] << endl;
return 0;
}
else if (n[0][0] > arr[m - 1][0])
{
int sum = 0;
int ans = 0;
int cnt = 0;
for (int i = m - 1; i >=0; --i)
{
if (sum > n[0][0])
{
ans -= (sum - n[0][0]) * arr[i+1][1];
cout << ans << endl;
return 0;
}
if (sum == n[0][0])
{
cout << ans << endl;
return 0;
}
sum += arr[i][0];
ans += arr[i][0] * arr[i][1];
cnt = i;
}
if (sum > n[0][0])
{
ans -= (sum - n[0][0]) * arr[cnt][1];
cout << ans << endl;
return 0;
}
if (sum < n[0][0])
{
cout << ans << endl;
return 0;
}
if (sum == n[0][0])
{
cout << ans << endl;
return 0;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int x = 0;
int zero = 0;
int five = 0;
for (int i = 0; i < n; i++)
{
cin >> x;
if (x == 0)
{
zero++;
}
else if (x == 5)
{
five++;
}
}
if (zero == 0)
{
printf("-1");
return 0;
}
if (zero > 0&&five/9>=1)
{
for (int i = 0; i < five / 9; i++)
{
printf("555555555");
}
for (int i = 0; i < zero; i++)
{
printf("0");
}
return 0;
}
else if(zero>0&&five/9==0)
{
printf("0");
return 0;
}
else
{
printf("-1");
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int cnt1, cnt0;
int pos1[1010], pos0[1010];
int main()
{
int t, n;
string s;
cin >> t;
while (t--)
{
cnt1 = 0;
cnt0 = 0;
cin >> n;
cin >> s;
for (int i = 0; i <n; i++)
{
if (s[i] == '1')
{
cnt1++;
pos1[cnt1] = i+1;
}
}
for (int i = n-1; i >=0; i--)
{
if (cnt1 == cnt0)
{
break;
}
if (s[i] == '0')
{
cnt0++;
pos0[cnt0] = i+1;
}
else if (s[i] == '1')
{
cnt1--;
}
}
if (cnt1 >= 1)
{
cout << "1" << endl;
cout << cnt1 + cnt0 << " ";
for (int i = 1; i <= cnt1; i++)
{
cout << pos1[i] << " ";
}
for (int i = cnt0; i > 0; i--)
{
cout << pos0[i] << " ";
}
cout << endl;
}
else
{
cout << "0" << endl;
}
}
return 0;
}