门牌制作

#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
int num = 0;
for(int i = 1; i <= 2020; i ++)
{
if(i % 10 == 2) num ++;
if(i / 10 % 10 == 2) num ++;
if(i / 100 % 10 == 2) num ++;
if(i / 1000 == 2) num ++;
}
cout << num;
return 0;
}

既约分数

#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
int x = 0;
for(int i = 1; i <= 2020; i ++)
{
for(int j = 1; j <= 2020; j ++)
{
if(__gcd(i, j) == 1)
{
x ++;
}
}
}
cout << x;
return 0;
}

蛇形填数

\begin{matrix} 1 & 2 & 6 & 7 & 15 & ... \\ 3 & 5 & 8 & 14 & ... \\ 4 & 9 & 13 & ... \\ 10 & 12 & ... \\ 11 & ... \\ ...   \end{matrix}1341011...  25912...6813...714...15......

#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main()
{
int s = 1;
for(int i = 1; i < 20; i ++)
{
s += 4 * i;
}
printf("%d",s);
return 0;
}

七段码

#include <bits/stdc++.h>
using namespace std;
string str = "0000000";
string vis;
int ans = 0;
//如何检查排列是否合法？
int umap[7][7];
void initmap()
{
memset(umap, 0, sizeof(umap));
umap[0][1] = umap[0][5] = 1;
umap[1][0] = umap[1][2] = umap[1][6] = 1;
umap[2][1] = umap[2][3] = umap[2][6] = 1;
umap[3][2] = umap[3][4] = 1;
umap[4][3] = umap[4][5] = umap[4][6] = 1;
umap[5][0] = umap[5][4] = umap[5][6] = 1;
umap[6][1] = umap[6][2] = umap[6][4] = umap[6][5] = 1;
}
void dfs(int curr)
{
vis[curr] = '0';//标记访问过了
for (int j = 0; j < 7; ++j)
{
if (umap[curr][j] == 1 && vis[j] == '1')
dfs(j);
}
}
bool check()
{
int cnt = 0;
for (int i = 0; i < 7;++i)
{
if(vis[i]=='1')
{
dfs(i);
++cnt;
}
}
return cnt == 1;
}
int main()
{
initmap();
for (int i = 0; i < 7; ++i)
{
sort(str.begin(), str.end());
str[6 - i] = '1';
do
{
vis = str;
if(check())
++ans;
} while (next_permutation(str.begin(), str.end()));
}
cout << ans << endl;
return 0;
}

跑步锻炼

#include<stdio.h>
#include<stdlib.h>
int main()
{
int ans=0;
int mon = 6;
int monthes[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i = 2000; i <= 2020; i ++)
{
if((i%4==0&&i%100!=0)||(i%400==0))
monthes[2]=29;
else
monthes[2]=28;
for(int month = 1; month <= 12; month ++)
{
for(int day = 1; day <= monthes[month]; day ++)
{
ans ++;
if(mon == 8)
mon = 1;
if(mon == 1 || day == 1)
ans ++;
mon ++;
if(i == 2020 && month == 10 && day == 1)//截至日期输出
printf("%d",ans);
}
}
}
return 0;
}

回文日期

2020 年春节期间，有一个特殊的日期引起了大家的注意：2020 年2 月2日。因为如果将这个日期按“yyyymmdd” 的格式写成一个8 位数是20200202，恰好是一个回文数。我们称这样的日期是回文日期。

2
20200202
20211203

20211202
21211212
20300302
21211212

#include <iostream>
using namespace std;
int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(int y, int m, int d)
{
if (d <= 0 || m <= 0 || m >= 13) return false;
if (m != 2)
{
if (d > months[m]) return false;
}
else
{
int days = months[2] + (y % 4 == 0 && y % 100 != 0 || y % 400 == 0);
if (d > days) return false;
}
return true;
}
int flip(int x)
{
int res = 0;
while (x)
{
res = res * 10 + x % 10;
x /= 10;
}
return res;
}
bool st1, st2;
int ans1, ans2;
int main()
{
int n;
cin >> n;
for (int i = n + 1; i <= 89991231; i++)
{
int year = i / 10000, month = i % 10000 / 100, day = i % 100;
if (check(year, month, day))
{
if (i % 10000 == flip(year) && !st1)
st1 = true, ans1 = i;
if (i % 10000 == flip(year) && (month / 10 == day / 10) && (month % 10 == day % 10) && !st2)
st2 = true, ans2 = i;
}
if (st1 && st2) break;
}
printf("%d\n%d\n", ans1, ans2);
return 0;
}

字串排序

2
4
100

bbaa
jihgfeeddccbbaa

#include<bits/stdc++.h>
using namespace std;
int V , len , now , cnt[27] , sum[27];
int get_max(int len){
return ((len - (len / 26 + 1)) * (len / 26 + 1) * (len % 26) + (26 - len % 26) * (len / 26) * (len - len / 26)) / 2;
}
bool check(int x , int n){
memset(cnt , 0 , sizeof(cnt));
for(int j = 26 ; j >= x + 1 ; j --) add1 += sum[j];
sum[x] ++ ;
for(int L = 1 ; L <= n ; L ++){
int ma = -1 , pos = 0 , num = 0;
for(int j = 26 ; j >= 1 ; j --){
if(L - 1 - cnt[j] + num > ma){
ma = L - 1 - cnt[j] + num;
pos = j;
}
num += sum[j];
}
add2 += ma , cnt[pos] ++;
}
return true;
}
else {
sum[x] -- ;
return false;
}
}
signed main()
{
string ans = "";
cin >> V;
for(int i = 1 ; ; i ++) {
if(get_max(i) >= V){
len = i;
break ;
}
}
for(int i = 1 ; i <= len ; i ++){
for(int j = 1 ; j <= 26 ; j ++){
if(check(j , len - i)){
ans += char(j + 'a' - 1);
break ;
}
}
}
cout << ans << '\n';
return 0;
}

成绩统计

7
80
92
56
74
88
100
0

71%
43%

#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <bitset>
using namespace std;
typedef long long ll;
int main()
{
int n, jige = 0, youxiu = 0;
cin >> n;
int m = n;
while(n --)
{
int a;
cin >> a;
if(a >= 60)
jige ++;
if(a >= 85)
youxiu ++;
}
double sum1 = jige * 1.00 / m * 100;
double sum2 = youxiu * 1.00 / m * 100;
printf("%.0lf%\n%.0lf%\n",sum1, sum2);
return 0;
}

子串分值和

ababc

28

#include <iostream>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
string s;
cin >> s;
ll total = 0;
int a[26];
memset(a,-1,sizeof(a));
a[s[0] - 'a'] = 0;
total += s.size();
for(int i=1;i<s.size();i++)
{
total += (i - a[s[i] - 'a']) * (s.size() - i);
a[s[i] - 'a'] = i;
}
cout << total;
return 0;
}

|
2月前

32 2
|
2月前
|

56 2
|
2月前
|

46 1
|
11月前

71 0
|
11月前
|
API

36 0
|
11月前

32 0
|
11月前

52 0
|
11月前

79 0
|
11月前
|

70 0
|
11月前
|
Java

65 0