1.打印栅栏
//来嵌套吧
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
cout<<'+';
for(int i=1;i<=n;i++){
for(int i=1;i<=k;i++){
cout<<'-';
}
cout<<'+';
}
return 0;
}
2.猴子吃桃
#include <iostream>
using namespace std;
int main() {
int n, a;
cin >> n >> a;
for (int i = n; i >= 1; i--) {
a--;
a *= 2;
}
cout << a << endl;
return 0;
}
3.数洞洞
#include<iostream>
using namespace std;
int main() {
int n;
cin >> n;
int cnt = 0;
for (int i = 1; i <= 4; i++) {
int x = n % 10;
n = n / 10;
if (x == 4 || x == 6 || x == 0 || x == 9)
cnt++;
else if (x == 8)
cnt += 2;
}
cout << cnt;
}
4.评委打分
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a[100001];
double s=0,max1=0,min1=20001;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
s+=a[i];
if(a[i]>max1) max1=a[i];
if(a[i]<min1) min1=a[i];
}
printf("%.2lf",(s-max1-min1)/(n-2));
return 0;
}
5.签到积分
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int res = 0, lst = 1;
for (int i = 0; i < s.size(); i ++) {
if (s[i] == 'Y') {
res += lst;
lst ++;
lst = min(5, lst);
} else {
lst = 1;
}
}
cout << res << endl;
return 0;
}
就是这些了。