那年我双手插兜,被打的不知道怎么还手!!!
:::
万恶的天梯赛😈
1-1 无所谓,我会出手
#include<iostream>
using namespace std;
int main() {
cout << "It doesn't matter,I'll do it.";
return 0;
}
1-2 数组总和
#include<iostream>
using namespace std;
typedef long long LL;
LL a[100000000];
int main() {
LL sum = 0, n,x;
cin >> n;
for (int i = 1; i <=n; i++)
{
cin >> x;
a[i] = x;
}
for (int i = 1; i <= n; i++)
{
sum += i * a[i];
}
cout << sum;
return 0;
}
1-3 捡到一个矩形
#include<iostream>
using namespace std;
typedef long long LL;
int main() {
int n, a, b, c, d,x,y;
cin >> n;
while (n--) {
cin >> a >> b >> c >> d;
cin >> x >> y;
if (x >= a && x <= c && y >= b && y <= d)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
1-4 字符转换
#include<iostream>
using namespace std;
int main() {
int a;
string ss;
cin >> ss;
for (int i = 0; i < ss.size(); i++)
{
a = ss[i] - 'a';
if((ss[i] + a + 1)<='z')
printf("%c", ss[i] + a+1);
else
printf("%c", ss[i] + a + 1-26);
}
return 0;
}
1-5 捡到了一个成绩
#include <algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
int main() {
double a[100], n,sum=0,o;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
sum += a[i];
}
int k = 0;
for (int i = 0; i < n; i++)
{
if (a[i] > (sum / n))k += a[i];
}
printf("%.3f\n%d", sum / n, k);
return 0;
}
1-6 炎爆
很无语这题,我用while显示段错误,用for就能过
#include <algorithm>
#include<iostream>
typedef long long LL;
using namespace std;
int a[101][101], n, q;
int main(){
cin >> n >> q;
for (int i = 1; i <= q; i++) {
int x, y; cin >> x >> y;
char op; cin >> op;
if (op == 'U') {
for (int j = x; j >= 1; j--) a[j][y] ++;
}
else if (op == 'R') {
for (int j = y; j <= n; j++) a[x][j] ++;
}
else if (op == 'D') {
for (int j = x; j <= n; j++) a[j][y] ++;
}
else {
for (int j = y; j >= 1; j--) a[x][j] ++;;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cout << a[i][j];
if (j != n) cout << ' ';
}
cout << endl;
}
return 0;
}
** 1-7 攻略迷宫 **
#include <algorithm>
#include<iostream>
typedef long long LL;
using namespace std;
int sum(int h, int m, int s)
{
return h * 3600 + m * 60 + s;
}//全部转化为秒方便统计。
int main()
{
int x, y;
int h1, m1, s1, h2, m2, s2;
scanf("%d%d%d:%d:%d%d:%d:%d", &x, &y, &h1, &m1, &s1, &h2, &m2, &s2);
int sum1 = sum(h1, m1, s1);
int sum2 = sum(h2, m2, s2);
int cnt = min((sum2 - sum1) / y, x);//返回 cnt 如果生命值小 也就是被打死了,反之就是没被打死
int res = sum1 + cnt * y;//刚开始的时间加上攻击次数×每次时间
printf("%d\n%02d:%02d:%02d\n", cnt, res / 3600, res % 3600 / 60, res % 60);//h,m,s
return 0;
}
1-8 去掉重复的数据
#include<iostream>
using namespace std;
int a[100001];
int main() {
int n, x;
int k = 1;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
a[x]++;
if (a[x] == 1) {
//pta破题要求贼多,这里是保证最后一个数据后面没空格
if (k == 0)
{
cout << ' ';
}
cout << x;
k = 0;
}
}
return 0;
}