ybt的坑
emmmm ybt 字符串处理 例2题解错了
AC自动机板子错了(据说)
另外字符串处理的题解写的我一脸懵逼
网站上eeeee
点击查看E. 1.排队接水
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
struct STU {
int t;
int num;
} a[1005];
bool cmp(STU a, STU b) {
if (a.t < b.t)
return true;
return false;
}
long long sum[1005], tot;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].t);
a[i].num = i + 1;
}
sort(a, a + n, cmp);
printf("%d", a[0].num);
for (int i = 1; i < n; i++) {
sum[i] = sum[i - 1] + a[i - 1].t;
tot += sum[i];
printf(" %d", a[i].num);
}
printf("\n%.2lf", tot * 1.0 / n * 1.0);
return 0;
}
//然鹅下面就是错的
//空格格式严格
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int n, t[10000], shunxu[10000], tem, a[100000], temp;
double pingjun, sum = 0, sum1, sum2;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &t[i]);
shunxu[i] = i;
sum2 += t[i];
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (t[i] > t[j]) {
temp = t[j];
t[j] = t[i];
t[i] = temp;
tem = shunxu[j];
shunxu[j] = shunxu[i];
shunxu[i] = tem;
}
}
}
for (int i = 1; i < n; i++) {
printf("%d ", shunxu[i]);
}
printf("%d", shunxu[n]);
for (int i = 2; i <= n; i++) {
t[i] = t[i - 1] + t[i];
}
for (int i = 1; i <= n; i++) {
sum1 += t[i];
}
sum = sum1 - sum2;
pingjun = sum / n * 1.0;
printf("\n%.2lf", pingjun);
return 0;
}
点击查看 C.【例题3】单词替换
//90pts
#include<bits/stdc++.h>
using namespace std;
string line;
string a,b;
int main()
{
getline(cin,line);
cin>>a>>b;
for(int i=0;i<line.size();i++)
{
int j=i;
string word;
while(j<line.size() && line[j]!=' ') word+=line[j++];
i=j;
if(word==a) cout<<b<<' ';
else cout<<word<<' ';
}
return 0;
}
//100pts
#include <bits/stdc++.h>
using namespace std;
string line;
string a, b;
int main() {
getline(cin, line);
cin >> a >> b;
for (int i = 0; i < line.size(); i++) {
int j = i;
string word;
while (j < line.size() && line[j] != ' ') word += line[j++];
i = j;
if (word == a)
cout << b << ' ';
else
cout << word << ' ';
}
return 0;
}