Advertisement

上海市计算机学会 2021年3月月赛(丙组)

阅读量:

第一道题:疫苗接种 AC

复制代码
 #include <iostream>

    
 #include <algorithm>
    
 using namespace std;
    
 int a, b, c;
    
 int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
 int main() {
    
 	scanf("%d-%d-%d", &a, &b, &c);
    
 	if (a%4==0&&a%100!=0 || a%400==0) days[2] = 29;
    
 	c += 14;
    
 	if (c > days[b]) c -= days[b], b++;
    
 	if (b > 12) b = 1, a += 1;
    
 	printf("%d-%d-%d", a, b, c);
    
 	return 0;
    
 }
    
    
    
    
    cpp
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/hQGNmWK9AryXMSxOvofij6sLCJYn.png)

第二道题:空心正方形 AC

复制代码
 #include <iostream>

    
 #include <algorithm>
    
 using namespace std;
    
 int n;
    
 int main() {
    
 	scanf("%d", &n);
    
 	for (int i = 1; i <= n; i++) {
    
 		for (int j = 1; j <= n; j++) {
    
 			if (i==1 || i==n || j==1 || j==n) printf("*");
    
 			else printf(" ");
    
 		}
    
 		puts("");
    
 	}
    
 	return 0;
    
 }
    
    
    
    
    cpp
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/1oy4VfrpNYhsOPubJCLQ5Rid0xM3.png)

第三道题:鸢尾花数 AC

复制代码
 #include <iostream>

    
 #include <algorithm>
    
 using namespace std;
    
 const int N = 1e5 + 7;
    
 bool v[N];
    
 void dfs(int x) {
    
 	int a = x/10%10;
    
 	int b = x%10;
    
 	int c = b - a + b;
    
 	if (c<0 || c>9) return ;
    
 	int xx = x*10 + c;
    
 	if (xx > 1e5) return ;
    
 	v[xx] = true;
    
 	dfs(xx);
    
 }
    
 int main() {
    
 	for (int i = 10; i <= 99; i++)
    
 		dfs(i);
    
 	int a, b, ct = 0;
    
 	scanf("%d%d", &a, &b);
    
 	for (int i = a; i <= b; i++) {
    
 		if (v[i]) {
    
 			printf("%d ", i);
    
 			ct++;
    
 		}
    
 	}
    
 	if (ct == 0) puts("-1");
    
 	return 0;
    
 }
    
    
    
    
    cpp
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/3VQPLzeNXIuF4w9cH1i0rafWhRpb.png)

第四道题:回文子串 AC

复制代码
 #include <iostream>

    
 #include <algorithm>
    
 using namespace std;
    
 string s;
    
 bool find(int a, int b) {
    
 	bool flag = true;
    
 	int ct = 0;
    
 	for (int i = a; i <= b; i++) {
    
 		if (s[i] != s[b-ct]) flag = false;
    
 		ct++;
    
 	}
    
 	if (flag == 1) return true;
    
 	else return false;
    
 }
    
 int main() {
    
 	int mx;
    
 	cin >> s;
    
 	for (int i = 0; i < s.size(); i++) {
    
 		for (int j = i+1; j < s.size(); j++) {
    
 			if (find(i, j))
    
 				mx = mx > j-i+1 ? mx : j-i+1;
    
 		}
    
 	}
    
 	printf("%d\n", mx);
    
 	return 0;
    
 }
    
    
    
    
    cpp
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/J6zMyjkc71vd84SD3eZ9RPqEBUTH.png)

第五道题:安装监控 AC

复制代码
 #include <iostream>

    
 #include <algorithm>
    
 using namespace std;
    
 int n, d, x;
    
 int ct, tail;
    
 int main () {
    
 	scanf("%d%d", &n, &d);
    
 	for (int i = 1; i <= n; i++) {
    
 		scanf("%d", &x);
    
 		if (tail < x) {
    
 			tail = x + d;
    
 			ct++;
    
 		}
    
 	}
    
 	printf("%d\n", ct);
    
 	return 0;
    
 }
    
    
    
    
    cpp
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/965D7juRU4ZecXPFhmHokO2Iyw8v.png)

若有更好的解,请私信与我~

全部评论 (0)

还没有任何评论哟~