#include<bits/stdc++.h> | |
using namespace std; | |
const double pp = acos(-1); // 等于 pi, 对精度要求高的题目有用 | |
int main() | |
{ | |
int a, b; | |
cin >> a >> b; | |
int c = (b + a) * (b + a); | |
printf("%0.10lf", pp* (double)c); | |
return 0; | |
} |

#include <bits/stdc++.h> | |
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
string s; | |
cin>>s; | |
int ans=0; | |
int a=0,b=0; | |
for(int i=0;i<s.size();i++) { | |
if(s[i]=='a') a++; | |
else b++; | |
if(a%10==0) ans++; | |
if(a<10) ans++; | |
if(b%10==0) ans++; | |
if(b<10) ans++; | |
} | |
printf("%d",ans); | |
} |
2000 年的 1 月 1 日,是那一年的第 1 天。
那么,2000 年的 5 月 4 日,是那一年的第几天?
#include <iostream> | |
#include <stdio.h> | |
using namespace std; | |
int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; | |
int y[2] = { 365,366 }; | |
bool judge(int i) { | |
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { | |
return true; | |
} | |
return false; | |
} | |
int main() | |
{ | |
int yy, mm, dd; | |
cin >> yy >> mm >> dd; | |
int sum = 0; | |
for (int i = 2022; i < yy; i++) { | |
if (judge(i)) sum += y[1]; | |
else sum += y[0]; | |
} | |
for (int i = 1; i < mm; i++) { | |
if (judge(yy)) a[2] = 29; | |
sum += a[i]; | |
} | |
sum += dd; | |
cout << sum; | |
return 0; | |
} |
#
小明对数位中含有 2、0、1、9 的数字很感兴趣(不包括前导 0)
在 1 到 40 中这样的数包括 1、2、9、10 至 32、39 和 40,共 28 个,他们的和是 574。
请问,在 1 到 n 中,所有这样的数的和是多少?
#include <iostream> | |
#include <stdio.h> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
cin >> n; | |
int res=0; | |
int sum = 0; | |
for (int i = 1; i <= n; i++) { | |
int num = i; | |
while (num) { | |
res = num % 10; | |
if (res == 2 || res == 1 || res == 9 || res == 0) { | |
sum += i; | |
break; | |
} | |
num /= 10; | |
} | |
} | |
cout << sum; | |
return 0; | |
} |
# 回文日期
20110101 | |
20111231 | |
1 | |
不能枚举日期然后进行判断,这样跟写一个日历似的,太复杂 | |
枚举所有年份,然后把它翻过来扩充成一个“日期”,然后看这个得到的“日期”是不是一个正常的日期格式,然后在看看是不是符合输入给的范围 | |
check函数来判断这个日期是不是一个正常的日期格式 | |
一个数除几个0,就是忽略掉这个数后面的几位 | |
一个数mod几个0,就是拿到这个数后面的几位 | |
#include <cstring> | |
#include <iostream> | |
using namespace std; | |
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | |
bool check(int date) | |
{ | |
int year = date / 10000; | |
int mouth = (date / 100) % 100; | |
int day = date % 100; | |
if(mouth < 0 || mouth > 12) return false; | |
if(day == 0 || mouth != 2 && day > days[mouth]) return false; | |
if(mouth == 2) | |
{ | |
int leap = year % 100 && year % 4 == 0 || year % 400 == 0; | |
if(day > days[mouth] + leap) return false; | |
} | |
return true; | |
} | |
int main() | |
{ | |
int date1, date2; | |
cin >> date1 >> date2; | |
int res = 0; | |
for(int i = 1000; i < 10000; i ++) | |
{ | |
int date = i, x = i; | |
for(int j = 0; j < 4; j ++ ) date = date * 10 + x % 10, x /= 10; | |
if(date1 <= date && date <= date2 && check(date)) res ++; | |
} | |
cout << res << endl; | |
return 0; | |
} |
刷题
123