试题A:门牌制作
#include<iostream>
using namespace std;
int main()
{
int res = 0;
for(int i = 1;i <= 2020;i ++)
{
int a = i % 10 , b = i / 10 % 10 ;
int c = i / 100 % 10 , d = i / 1000;
if(a == 2) res ++;
if(b == 2) res ++;
if(c == 2) res ++;
if(d == 2) res ++;
}
cout<<res;
return 0;
}
答案:624
试题B:既约分数
#include<iostream>
using namespace std;
int gcd(int x,int y)
{
return y == 0 ? x : gcd(y,x%y);
}
int main()
{
int res = 0;
for(int i = 1;i <= 2020;i ++)
for(int j = i;j <= 2020;j ++)
{
if(gcd(i,j) == 1 )
res ++;
if(i != j&&gcd(j,i) == 1)
res ++;
}
cout<<res;
return 0;
}
答案:2481215
试题C:蛇形填数
#include<iostream>
using namespace std;
int a[110][110];
int m = 1;
int main()
{
for(int t = 0;t <= 100;t ++)
{
if(t % 2 == 1)
for(int i = 0,j = t;i <= t;i ++,j --)
{
a[i][j] = m ++;
//cout<<i<<" "<<j<<":"<<a[i][j]<<endl;
}
else
{
for(int i = t,j = 0;i >= 0;i --,j ++)
{
a[i][j] = m ++;
//cout<<i<<" "<<j<<":"<<a[i][j]<<endl;
}
}
}
cout<<a[19][19];
return 0;
}
答案:761
试题D:跑步锻炼
#include<iostream>
using namespace std;
int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int week = 6;
int main()
{
int res = 0;
for(int y = 2000;y <= 2020;y ++)
{
int leap = y % 4 == 0 && y % 100 || y % 400 == 0;
for(int m = 1;m <= 12;m ++)
{
int sum = days[m];
if(m == 2) sum += leap;
for(int d = 1;d <= sum;d ++)
{
if(d == 1 || week == 1) res += 1;
res += 1;
if(y == 2020 && m == 10 && d == 1 && week == 4)
{
cout<<res;
return 0;
}
week ++;
if(week > 7) week = 1;
}
}
}
}
答案:8879
试题E:七段码
Updating...
答案:Updating...
试题F:成绩统计
#include <iostream>
#include <cstring>
#include <algorithm>
#define N 10010
using namespace std;
int q[N],n;
int main()
{
cin>>n;
float a = 0 , b = 0;
for (int i = 0; i < n; i ++ )
{
cin>>q[i];
if(q[i] >= 60) a ++;
if(q[i] >= 85 && q[i] <= 100) b ++;
}
printf("%.f%% %.f%%",a/n*100,b/n*100);
return 0;
}
试题G:回文日期
直接看我以前做的吧!我这里就不再重写了!
链接: https://www.acwing.com/solution/content/42745/
试题H:子串分值
听说暴力,能出奇迹!
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#define N 10010
using namespace std;
char s[N];
int temp[N];
int main()
{
cin>>s;
int res = 0 , len = strlen(s);
for (int i = 0; i < len; i ++ )
{
memset(temp,0,sizeof temp);
temp[s[i]] ++;
int flag = 1;
res ++;
for (int j = i + 1; j < len; j ++ )
if(!temp[s[j]])
{
flag++;
temp[s[j]] ++;
res += flag;
}
else
res += flag;
}
cout<<res<<endl;
return 0;
}
过了 60% 的数据
试题I:平面切分
越是最后的题,越短越恐怖。。。
反正AcWing上面通过率比较乐观!
试题J:字串排序
对于最后一道题,能骗就骗。。。
你要真执意搞懂,去CSDN上面看大佬的思考!