第一题:
#include <iostream>
using namespace std;
int n;
int a[4];
int Y(int i)
{
if (i % 10 == 7)
return 1;
if ((i / 10) % 10 == 7)
return 1;
if (i / 100 == 7)
return 1;
return 0;
}
int main()
{
scanf(“%d”, &n);
for (int i = 1; i <= n; i++)
{
if (i % 7 == 0 || Y(i))
{
switch (i % 4)
{
case 0:
a[3]++;
break;
case 1: // 甲
a[0]++;
break;
case 2:
a[1]++;
break;
case 3:
a[2]++;
break;
}
n++;
}
}
for (int i = 0; i < 4; i++)
printf(“%d\n”, a[i]);
return 0;
}
第二题:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, c_sum[5];
vector<pair<int, int>> a;
int is_OK(int x, int y)
{
if (find(a.begin(), a.end(), make_pair(x, y + 1)) == a.end())
return 0;
if (find(a.begin(), a.end(), make_pair(x, y – 1)) == a.end())
return 0;
if (find(a.begin(), a.end(), make_pair(x + 1, y)) == a.end())
return 0;
if (find(a.begin(), a.end(), make_pair(x – 1, y)) == a.end())
return 0;
return 1;
}
void Points(int x, int y)
{
int sum = 0;
if (find(a.begin(), a.end(), make_pair(x + 1, y + 1)) != a.end())
sum++;
if (find(a.begin(), a.end(), make_pair(x + 1, y – 1)) != a.end())
sum++;
if (find(a.begin(), a.end(), make_pair(x – 1, y + 1)) != a.end())
sum++;
if (find(a.begin(), a.end(), make_pair(x – 1, y – 1)) != a.end())
sum++;
c_sum[sum]++;
}
int main()
{
scanf(“%d”, &n);
for (int x, y, i = 0; i < n; i++)
{
scanf(“%d%d”, &x, &y);
a.push_back(make_pair(x, y));
}
for (int i = 0; i < n; i++)
if (is_OK(a[i].first, a[i].second))
Points(a[i].first, a[i].second);
for(int i=0;i<5;i++)
printf(“%d\n”,c_sum[i]);
return 0;
}
水得一