P5716 [深基3.例9] 月份天数
#include <cstdio>
int main()
{
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int y, m;
scanf("%d%d", &y, &m);
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) days[1] = 29;
printf("%d\n", days[m - 1]);
return 0;
}
P1046 [NOIP2005 普及组] 陶陶摘苹果
#include <cstdio>
int main()
{
int h[10];
for (int i = 0; i < 10; i++) scanf("%d", &h[i]);
int t;
scanf("%d", &t);
int ans = 0;
for (int i = 0; i < 10; i++) {
if (t + 30 >= h[i]) ans++;
}
printf("%d\n", ans);
return 0;
}
P1089 [NOIP2004 提高组] 津津的储蓄计划
#include <cstdio>
int main()
{
int b[13];
for (int i = 1; i <= 12; i++) {
scanf("%d", &b[i]);
}
int save = 0;
int money = 0;
for (int i = 1; i <= 12; i++) {
money += 300;
money -= b[i];
if (money < 0) {
printf("%d\n", -i);
break;
}
save += money / 100 * 100;
money = money % 100;
}
if (money >= 0) {
money += save / 5 * 6;
printf("%d\n", money);
}
return 0;
}
P1428 小鱼比可爱
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int a[105];
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
int x = 0;
for (int j = 1; j < i; j++) {
if (a[j] < a[i]) ++x;
}
printf("%d ", x);
}
return 0;
}
P1427 小鱼的数字游戏
#include <cstdio>
int main()
{
int x;
int a[105];
int len = 0;
while (scanf("%d", &x)) {
if (x == 0) break;
a[++len] = x;
}
for (int i = len; i >= 1; i--) printf("%d ", a[i]);
return 0;
}
P5727 [深基5.例3] 冰雹猜想
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int a[1000];
int len = 0;
while (n != 1) {
a[++len] = n;
if (n % 2 == 1) n = 3 * n + 1;
else n = n / 2;
}
printf("1");
for (int i = len; i >= 1; i--) printf(" %d", a[i]);
return 0;
}
P1047 [NOIP2005 普及组] 校门外的树
#include <cstdio>
int main()
{
int l, m;
int road[10005];
scanf("%d%d", &l, &m);
for (int i = 0; i <= l; i++) road[i] = 1;
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
for (int j = u; j <= v; j++) road[j] = 0;
}
int ans = 0;
for (int i = 0; i <= l; i++) ans += road[i];
printf("%d\n", ans);
return 0;
}
P5728 [深基5.例5] 旗鼓相当的对手
#include <cstdio>
int c[1005], m[1005], e[1005];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d%d%d", &c[i], &m[i], &e[i]);
int ans = 0;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j) {
int dc = c[i] - c[j];
int dm = m[i] - m[j];
int de = e[i] - e[j];
int dsum = (c[i] + m[i] + e[i]) - (c[j] + m[j] + e[j]);
if (dc >= -5 && dc <= 5)
if (dm >= -5 && dm <= 5)
if (de >= -5 && de <= 5)
if (dsum >= -10 && dsum <= 10)
ans++;
}
printf("%d\n", ans);
return 0;
}
P5729 [深基5.例7] 工艺品制作
#include <cstdio>
int a[25][25][25];
int main()
{
int w, x, h;
scanf("%d%d%d", &w, &x, &h);
int q;
scanf("%d", &q);
int cur = w * x * h;
while (q > 0) {
q--;
int x1, y1, z1, x2, y2, z2;
scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2);
for (int i = x1; i <= x2; ++i)
for (int j = y1; j <= y2; ++j)
for (int k = z1; k <= z2; ++k) {
if (a[i][j][k] == 0) --cur;
a[i][j][k] = 1;
}
}
printf("%d\n", cur);
return 0;
}
P2550 [AHOI2001] 彩票摇奖
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int num[35] = {0};
int award[10] = {0};
for (int i = 0; i < 7; i++) {
int id;
scanf("%d", &id);
num[id] = 1;
}
for (int i = 0; i < n; i++) {
int hit = 0;
for (int j = 0; j < 7; j++) {
int id;
scanf("%d", &id);
if (num[id] == 1) hit++;
}
award[7 - hit]++;
}
for (int i = 0; i <= 6; i++) printf("%d ", award[i]);
return 0;
}
P1554 梦中的统计
#include <cstdio>
int main()
{
int m, n;
scanf("%d%d", &m, &n);
int cnt[10] = {0};
for (int i = m; i <= n; i++) {
int t = i;
while (t > 0) {
cnt[t % 10]++;
t = t / 10;
}
}
for (int i = 0; i <= 9; i++) printf("%d ", cnt[i]);
return 0;
}
P1614 爱与愁的心痛
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 3005;
const int INF = 1e9;
int a[MAXN];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int ans = INF;
for (int i = 1; i <= n - m + 1; i++) {
int sum = 0;
for (int j = i; j < i + m; j++) sum += a[j];
ans = min(ans, sum);
}
printf("%d\n", ans);
return 0;
}
标签:main,int,scanf,d%,++,数组,2.1,include,代码
From: https://www.cnblogs.com/ronchen/p/17577009.html