CSDN编程竞赛报名地址:https://edu.csdn.net/contest/detail/16
第一次参加CSDN的竞赛,好像是某次登录的时候看到有个竞赛链接就点进去报名了,然后今天早上收到短信才想到有这么一个事,就起来做题了,不然还赖在床上不想动。
整体题目是偏简单的,也是第一次参加这个竞赛并不熟悉,第一题就杠上了,用了CSDN默认的输入输出模板死活过不去,浪费了好多时间,后来想想还是妥协了,自己写算了 😂
浏览了下还有考试报告,话不多说,直接贴下自己的解题代码,有些题目用python会快很多,但想想反正第一题都浪费了那么多时间,肯定落后了,就都用C语言去解了,下次再用python。
一、题目名称:严查枪火
X国最近开始严管枪火。 像是“ak”,“m4a1”,“skr”。都是明令禁止的。 现在小Q查获了一批违禁物品其中部分是枪支。
小Q想知道自己需要按照私藏枪火来关押多少人。 (只有以上三种枪被视为违法)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int n;
scanf("%d", &n);
int result = 0;
char s[1000];
for(int i = 0; i < n; i++){
scanf("%s", s);
if(strcmp(s, "ak") == 0 || strcmp(s, "m4a1") == 0 || strcmp(s, "skr") == 0)
result++;
}
printf("%d", result);
return 0;
}
二、题目名称:鬼画符门
鬼画符门,每年都会统计自己宗门鬼画符消耗的数量,往年一直是大师兄管理, 但是这次鬼艺接手了, 你能帮鬼艺写一个
程序统计每年消耗数量最多的鬼画符吗?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
int main() {
int n;
scanf("%d", &n);
char s[100];
int c = 1;
char name[1000][100];
int count[1000];
memset(count, 0, sizeof(count));
if(n == 0){
return 0;
}
scanf("%s", name[0]);
int j = 0;
for (int i = 1; i < n; i++){
scanf("%s", s);
for(j = 0; j < c; j++) {
if(strcmp(s, name[j]) == 0){
count[j]++;
break;
}
}
if(j == c){
strcpy(name[j], s);
c++;
}
}
int m = 0;
int result = 0;
for(int i = 0; i < c; i++){
if(count[i] > m){
m = count[i];
result = i;
}
}
printf("%s\n", name[result]);
return 0;
}
第三题之后就用默认的输入输出模板啦,这一题用python的话基本一个replace函数就解决大部分问题了
三、题目名称:收件邮箱
已知字符串str,str表示邮箱的不标准格式。 其中”.”会被记录成”dot”,”@”记录成”at”。 写一个程序将str转化成可用
的邮箱格式。(可用格式中字符串中除了开头结尾所有”dot”,都会被转换,”at”只会被转化一次,开头结尾的不转化)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
char * solution(char m[]){
char *result;
int l = strlen(m);
result = (char*)malloc(l + 1);
for(int i = 1; i < l; i++){
if(m[i] == 'a'){
if(m[i+1] == 't' && i!=l-2){
m[i] = '@';
m[i+1] = ' ';
break;
}
}
}
for(int i = 1; i < l; i++){
if(m[i] == 'd'){
if(m[i+1] == 'o' && m[i+2] == 't' && i!=l-3){
m[i++] = '.';
m[i++] = ' ';
m[i] = ' ';
}
}
}
strcpy(result, m);
int c = 0;
for(int i = 0; i < l; i++){
if(m[i] == ' '){
strcpy(result + i - c, m + i + 1);
c++;
}
}
return result;
}
int main() {
char m[1000];
scanf("%s", m);
char *result = solution(m);
printf("%s", result);
free(result);
return 0;
}
四、题目名称:最长递增的区间长度
给一个无序数组,求最长递增的区间长度。如:[5,2,3,8,1,9] 最长区间 2,3,8 长度为 3
#include <stdio.h>
#include <stdlib.h>
int solution(int n, int arr[]){
int result;
result = 1;
int c = 1;
for(int i = 1; i < n; i++){
if(arr[i] > arr[i-1]){
c++;
}else{
if(c > result)
result = c;
c = 1;
}
}
if(c > result)
result = c;
return result;
}
int main() {
int n;
scanf("%d", &n);
int *arr;
arr = (int*)malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int result = solution(n, arr);
printf("%d", result);
return 0;
}