由浅入深
P8717 [蓝桥杯 2020 省 AB2] 成绩分析
cpp
#include <iostream>
using namespace std;
int num;
double sum;
int maxs,mins;
int n;
int main()
{
mins=1e9;
maxs=-1e9;
sum=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>num;
sum+=num;
maxs=max(maxs,num);
mins=min(mins,num);
}
cout<<maxs<<endl;
cout<<mins<<endl;
printf("%.2lf",sum/n);
return 0;
}
P8761 [蓝桥杯 2021 国 BC] 大写
直接用ASCII数的性质,记得要char强转一下
cpp
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<(int)s.size();i++)
{
if(s[i]>='a'&&s[i]<='z') cout<<char(s[i]+'A'-'a');
else cout<<s[i];
}
return 0;
}
P8711 [蓝桥杯 2020 省 B1] 整除序列
cpp
#include <iostream>
using namespace std;
long long n;
int main()
{
cin>>n;
while(n>=1)
{
cout<<n<<" ";
n/=2;
}
return 0;
}
P8722 [蓝桥杯 2020 省 AB3] 日期识别
用map容器1把字符和数字对应
cpp
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string,int> si;
string s;
int main()
{
cin>>s;
string s1=s.substr(0,3);
string
Jan1="Jan",Feb1="Feb",Mar1="Mar",Apr1="Apr",May1="May",Jun1="Jun",
Jul1="Jul",Aug1="Aug",Sep1="Sep",Oct1="Oct",Nov1="Nov",Dec1="Dec";
si[Jan1]=1,si[Feb1]=2,si[Mar1]=3,si[Apr1]=4,si[May1]=5;
si[Jun1]=6,si[Jul1]=7,si[Aug1]=8,si[Sep1]=9,si[Oct1]=10,si[Nov1]=11,si[Dec1]=12;
cout<<si[s1]<<" ";
if(s[3]!='0') cout<<s[3];
cout<<s[4];
return 0;
}
P8680 [蓝桥杯 2019 省 B] 特别数的和
cpp
#include <iostream>
using namespace std;
int n;
int sum;
int flag;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int a=i;
while(a>0)
{
int b=a%10;
if(b==2||b==0||b==1||b==9)
{
sum+=i;
break;
}
a/=10;
}
}
cout<<sum<<endl;
return 0;
}