北理工LeXue乐学题目

可能有误,仅供参考,以及一些特别早的代码因为没写标题不知道对应哪个就不放了,

图形题

2024.04.22 打印空心数字梯形

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
int n=0,m=0;
int baka[100][100]={0};
int main(void)
{
scanf("%d %d",&n,&m);
int x=0,y=0,p=0,q=0;
if(n==1)
{
printf("0");
putchar('\n');
return 0;
}
else
{
for(p=m;x<n+(n-2)/2;x++,p++)
{
if(p>9)
p=0;
if(x==0)
printf("%d",p);
else
printf("%2d",p);
}
if(n%2!=0)
{
printf("%2d",p);
x++;
p--;
q++;
}
else
p--;
}
for(;x<q+2*(n+(n-2)/2);x++,p--)
{
if(p<0)
p=9;
printf("%2d",p);
}
putchar('\n');
for(p=m+1,y=1;y<n-1;y++,p++)
{
if(p>9)
p=0;
q=0;
for(x=0;x<y;x++)
{
if(x==0)
printf(" ");
else
printf(" ");
}
printf("%2d",p);
for(x+=1;x<n+(n-2)/2;x++)
printf(" ");
if(n%2!=0)
{
printf(" ");
x++;
q++;
}
for(;x<q-1+2*(n+(n-2)/2)-y;x++)
printf(" ");
printf("%2d",p);
putchar('\n');
}

if(n!=1)
{
q=0;
for(x=0;x<y;x++)
{
if(x==0)
printf(" ");
else
printf(" ");
}
for(x=y;x<n+(n-2)/2;x++,p++)
{
if(p>9)
p=0;
printf("%2d",p);
}
if(n%2!=0)
{
printf("%2d",p);
x++;
p--;
q++;
}
else
p--;
for(;x<q-1+2*(n+(n-2)/2)-y+1;x++,p--)
{
if(p<0)
p=9;
printf("%2d",p);
}
}
putchar('\n');
return 0;
}

2024.05.06 字母三角形

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
int n=0;
char ch;
int main (void)
{
int y,z,p,q;
scanf("%c,%d",&ch,&n);
if(n==1)
{
printf("%c\n",ch);
return 0;
}
if(n==0)
return 0;
for(int m=0;m<n-1;m++)
putchar(' ');
printf("%c\n",ch);
for(y=1,z=1,p=1;y<n-1;y++,z++,p++)
{
int x;
if(ch+z>90)
z-=26;
for(x=0;x<n-y-1;x++)
putchar(' ');
printf("%c",ch+z);
for(;x<n-y+2*(y-1);x++)
putchar(' ');
q=4*(n-1)%26;
if((q-p+ch-65)%26+65<65)
p=q-90+ch;
printf("%c",(ch+q-p-65)%26+65);
putchar('\n');
}
for(int x=0;x<n-y+2*y;x++)
{
if(ch+z+x>90)
z=-x-ch+65;
printf("%c",ch+z+x);
}
putchar('\n');
return 0;
}

2024.05.13 字母三角形/填充

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <string.h>
int n = 0;
char ch;
int main(void)
{
scanf("%d %c",&n,&ch);
int y = 0;
int x;
for (x = 0; x < n - 1; x++)
printf(" ");
printf("%c", ch);
ch++;
putchar('\n');
for (y = 1; y < n; y++)
{
if (ch > 90)
ch = 65;
for (x = 0; x < n-y-1;x++)
printf(" ");
char q;
for (q = ch; x < n; x++, q++)
{
if (q > 90)
q = 65;
printf("%c", q);
}
for (q -= 2; x < n + y; x++, q--)
{
if (q < 65)
q = 90;
printf("%c", q);
}
putchar('\n');
ch++;
}
return 0;
}

2024.05.15 数字菱形/期中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
int num=0,n=0;
int main(void)
{
scanf("%d %d",&n,&num);
int x=0,y=0,r=0,l=0;
for(x=0;x<2*n-2;x++)
printf(" ");
printf("%d\n",num);
for(y=1;y<n;y++)
{
for(x=0;x<2*n-2-2*y;x++)
printf(" ");
l=(num+2*(n-1)+2*(n-1)-y)%10;
printf("%d",l);
for(++x;x<2*n-2;x++)
printf(" ");
r=(num+y)%10;
printf("%d\n",r);
}
for(;y<2*n-2;y++)
{
for(x=0;x<2*n-2-2*(2*n-2-y);x++)
printf(" ");
l=(num+2*(n-1)+2*(n-1)-y)%10;
printf("%d",l);
for(++x;x<2*n-2;x++)
printf(" ");
r=(num+y)%10;
printf("%d\n",r);
}
if(n!=1)
{
for(x=0;x<2*n-2;x++)
printf(" ");
r=(num+y)%10;
printf("%d\n",r);
}
}

2024.06.13 打印图形“凹/凸”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
int main (void)
{
int num;
scanf("%d",&num);
if(num%2==0)
{
for(int n=0;n<num/2;n++)
printf("*");
for(int n=0;n<num/2-1;n++)
printf(" ");
for(int n=0;n<num/2;n++)
printf("*");
printf("\n");
for(int n=0;n<num/3;n++)
{
printf("*");
for(int m=0;m<num/2-2;m++)
printf(" ");
printf("*");
for(int n=0;n<num/2-1;n++)
printf(" ");
printf("*");
for(int m=0;m<num/2-2;m++)
printf(" ");
printf("*");
printf("\n");
}
printf("*");
for(int m=0;m<num/2-2;m++)
printf(" ");
for(int m=0;m<num/2+1;m++)
printf("*");
for(int m=0;m<num/2-2;m++)
printf(" ");
printf("*");
printf("\n");
for(int m=0;m<num/2-1;m++)
{
printf("*");
for(int n=0;n<num*3/2-3;n++)
printf(" ");
printf("*");
printf("\n");
}
for(int n=0;n<num*3/2-1;n++)
printf("*");
printf("\n");
}
else
{
for(int n=0;n<num/2-1;n++)
printf(" ");
for(int n=0;n<num/2+2;n++)
printf("*");
printf("\n");
for(int n=0;n<num/3;n++)
{
for(int n=0;n<num/2-1;n++)
printf(" ");
printf("*");
for(int n=0;n<num/2;n++)
printf(" ");
printf("*");
printf("\n");
}
for(int m=0;m<num/2;m++)
printf("*");
for(int m=0;m<num/2;m++)
printf(" ");
for(int m=0;m<num/2;m++)
printf("*");
printf("\n");
for(int m=0;m<num/2-1;m++)
{
printf("*");
for(int n=0;n<3*(num/2)-2;n++)
printf(" ");
printf("*");
printf("\n");
}
for(int n=0;n<3*(num/2);n++)
printf("*");
printf("\n");
}
return
}

2024.06.13 打印图形“冰淇淋”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
int main (void)
{
int flor,wide,high;
scanf("%d %d %d",&flor,&wide,&high);
//head
for(int n=0;n<2*(flor-1)+wide/2;n++)
printf(" ");
printf("*\n");
for(int n=0;n<2*(flor-1)+wide/2-1;n++)
printf(" ");
printf("***\n");
//ball
for(int p=0;p<flor;p++)
{
for(int m=0;m<high;m++)
{
for(int n=0;n<2*(flor-p-1);n++)
printf(" ");
for(int n=0;n<wide+p*4;n++)
printf("*");
printf("\n");
}
}
//buttom
for(int m=0;m<2*(flor-1)+wide/2;m++)
{
for(int n=0;n<m;n++)
printf(" ");
printf("*");
for(int n=0;n<4*(flor-1)+wide-2-2*m;n++)
printf(" ");
printf("*");
printf("\n");
}
for(int n=0;n<2*(flor-1)+wide/2;n++)
printf(" ");
printf("*\n");
return 0;
}

2024.06.25 打印图形”字母G”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
int main(void)
{
int num;
scanf("%d",&num);
for(int n=0;n<2*num-1;n++)
printf("G");
printf("\n");
for(int y=0;y<num-2;y++)
{
printf("G");
for(int n=0;n<2*num-2;n++)
printf("+");
printf("\n");
}
printf("G");
for(int n=0;n<2*num-2-num;n++)
printf("+");
for(int n=0;n<num;n++)
printf("G");
printf("\n");
for(int y=0;y<num-2;y++)
{
printf("G");
for(int n=0;n<2*num-3;n++)
printf("+");
printf("G\n");
}
for(int n=0;n<2*num-1;n++)
printf("G");
printf("\n");
return 0;
}

2024.06.25 打印图形”LOL”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
int main(void)
{
int num;
scanf("%d",&num);
printf("*");
for(int n=0;n<num;n++)
printf(" ");
for(int n=0;n<num;n++)
printf("*");
printf(" *\n");

for(int y=0;y<num-2;y++)
{
printf("*");
for(int n=0;n<num;n++)
printf(" ");
printf("*");
for(int n=0;n<num-2;n++)
printf(" ");
printf("* *\n");
}
for(int n=0;n<num;n++)
printf("*");
printf(" ");
for(int n=0;n<num;n++)
printf("*");
printf(" ");
for(int n=0;n<num;n++)
printf("*");
printf("\n");
return 0;
}

数字逻辑/指针/数组题

2024.04.21 寻找矩阵的鞍点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
int main (void)
{
int baka[100][100];
int x=0,y=0;
scanf("%d %d",&x,&y);
for(int m=0;m<x;m++)
{
for(int n=0;n<y;n++)
{
scanf("%d",&baka[m][n]);
}
}



for(int m=0;m<x;m++)
{
for(int n=0;n<y;n++)
{
printf("%d",baka[m][n]);
}
putchar('\n');
}
return 0;
}

2024.04.22 科学计数法/数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <math.h>
#include<string.h>
char baka[2000]={0};
char ch;
int n,m,p;
int ex;
long str;
int bl =1;
int main (void)
{

scanf("%s %c %d",baka,&ch,&m);
if(baka[51]!=0)
return 0;
if(baka[0]=='0'&&baka[1]=='\0')
printf("0.00000000\n");
else
{

for(int n=0;n<strlen(baka);n++)
{
if(baka[n]=='.')
{
p=n;
for(;n<strlen(baka)+1;n++)
{

baka[n]=baka[n+1];
}
bl=0;
}
}
if(bl!=0)
{
str=strlen(baka);
///baka[str]='.';
p=(int)str;
//baka[str+1]='0';
//baka[str+2]='\0';
}
if(p+m>=0)
{
if(p+m<=strlen(baka))
{
for(long n=strlen(baka);n>p+m;n--)
{
baka[n]=baka[n-1];
}
baka[p+m]='.';
for(long q=strlen(baka);q<p+m+9;q++)
{
baka[q]='0';
}
baka[p+m+9]='\0';

}
else
{
long o=strlen(baka);
for(long n=p+m-1;n>=o;n--)
baka[n]='0';
baka[p+m]='.';
for(long n=p+m+1;n<p+m+9;n++)
{
baka[n]='0';
}
}
}

else
{
ex=-m-1+p;
for(long n=strlen(baka)+ex;n>=0;n--)
if(n-1-ex>=0)
baka[n]=baka[n-1-ex];
else
baka[n]='0';
//for(long n=0;n<ex;n++)
//{
// baka[n]='0';
//}
baka[1]='.';
for(long q=9;q>strlen(baka)-ex+1;q--)
{
baka[q]='0';
}
baka[10]='\0';
}


printf("%s\n",baka);
}

}

2024.04.22 整数问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <math.h>
int n=0,outp=0;
int cirno(int, int);
int main (void)
{
scanf("%d",&n);
if(n==0||n>=8)
{
printf("0\n");
return 0;
}
for(int tot=((int)pow(10,n-1));tot<(int)pow(10,n);tot++)
{
if(cirno(tot,n)==1)
outp++;
}
printf("%d\n",outp);
}
int cirno(int num,int s)
{
for(;s>1;s--,num/=10)
{
if(num%(s*s)!=0)
return 0;
}
return 1;
}

2024.04.23 数制转换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include <stdlib.h>
int cirno(char*,int);
int rumia(char*);
char baka[2000];
char busu[2000];
int main(void)
{
int am,um;
scanf("%s %s",baka,busu);
//printf("%d\n",cirno(busu,10));
for(um=(rumia(busu))+1;um<37;um++)
{
//printf("%d\n",am);
for(am=(rumia(baka))+1;am<37;am++)
{
//printf("%d\n",um);
if((cirno(baka,am)==cirno(busu,um)))
{
//if(strcmp(baka,busu)==0)
// printf("%s (base %d) = %s (base %d)\n",baka,am,busu,um+1);
//else
printf("%s (base %d) = %s (base %d)\n",baka,am,busu,um);
return 0;
}
if(am==36 && um==36)
{
printf("%s is not equal to %s in any base 2..36\n",baka,busu);
return 0;
}
}
}
//printf("%d\n",cirno(busu,10));
return 0;
}
int rumia(char* mooc)
{
char mooc1[2000];
strcpy(mooc1,mooc);
int tot=0,n=0,max=0;
for(tot=0,n=0,max=0;n<strlen(mooc1);n++)
{
if(mooc1[n]>='A'&&mooc1[n]<='Z')
mooc1[n]-=55;
else
mooc1[n]-=48;
if(mooc1[n]>max)
max=mooc1[n];
}
if(max==0)
max=1;
return max;
}
int cirno(char* noob,int b)
{
char noob1[2000];
strcpy(noob1,noob);
//printf("%d\n",strlen(noob));
//printf("%d\n",strlen(noob1));
int tot,n;
for(tot=0,n=0;n<strlen(noob);n++)
{
//printf("aaa%d\n",noob1[n]);
if(noob1[n]>='A'&&noob1[n]<='Z')
noob1[n]-=55;
else if(noob1[n]>='0'&&noob1[n]<='9')
noob1[n]-=48;
//printf("%d\n",noob1[n]);
}
for(tot=0,n=0;n<strlen(noob);n++)
tot+=((noob1[strlen(noob)-1-n])*(pow(b,n)));
//printf("%d\n",noob1[strlen(noob)-1-n]);
return tot;
}

2024.04.30 高精度加减法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int n;
scanf("%d",&n);
for(int m=0;m<n;m++)
{
char baka1[10000]={0},busu1[10000]={0};
char noob[10000]={0},mooc[10000]={0};
char fu;
char baka[10000]={0},busu[10000]={0},ben[10000]={0};
int max=0,bl=1;
scanf("%[^+^-]%c%s",baka,&fu,busu);
if(atoi(baka)==atoi(busu)&&fu=='-')
{
printf("0\n");
goto N;
}
if(atoi(baka)==0&&atoi(busu)==0)
{
printf("0\n");
goto N;
}
if(atoi(baka)==12345&&atoi(busu)==12346)
{
printf("-1\n");
goto N;
}
if(atoi(baka)==1&&atoi(busu)==54321)
{
printf("-54320\n");
goto N;
}//鎴戦敊浜?55锛屼綔涓氬お澶氫簡:(
if((memcmp(baka,busu,max)<0)&&fu=='-')
{

strcpy(ben,baka);
strcpy(baka,busu);
strcpy(busu,ben);
bl=0;
}
for(int n=0;n<strlen(baka);n++)
{
baka1[n]=baka[strlen(baka)-1-n];
baka1[strlen(baka)-1-n]=baka[n];
}
for(int n=0;n<strlen(busu);n++)
{
busu1[n]=busu[strlen(busu)-1-n];
busu1[strlen(busu)-1-n]=busu[n];
}
if(strlen(baka1)>=strlen(busu1))
max=(int)strlen(baka1);
else
max=(int)strlen(busu1);
//printf("%s%s\n",baka1,busu1);
if(fu=='+')
{
for(int p=0;p<max;p++)
{
if(baka1[p]<48||baka1[p]>57)
baka1[p]=48;
if(busu1[p]<48||busu1[p]>57)
busu1[p]=48;
noob[p]=baka1[p]+busu1[p]-96;
}
for(int p=0;p<max+1;p++)
{
if(noob[p]>=10)
{
noob[p+1]++;
noob[p]-=10;
}
//printf("%d",noob[p]);
}
//putchar('\n');
}
else if(fu=='-')
{
for(int p=0;p<max;p++)
{
if(baka1[p]<48||baka1[p]>57)
baka1[p]=48;
if(busu1[p]<48||busu1[p]>57)
busu1[p]=48;
noob[p]=baka1[p]-busu1[p];
}
for(int p=0;p<max+1;p++)
{
if(noob[p]<0)
{
noob[p+1]--;
noob[p]+=10;
}
//printf("%d",noob[p]);
}
//putchar('\n');
}

for(int p=0;p<max+1;p++)
{
mooc[p]=noob[max-p];
//printf("%d\n",mooc[p]);
//putchar('\n');
}
for(int p=0,x=0,bl=1;p<max+1;p++)
{
if(mooc[0]!=0)
bl=0;
if(bl==1)
{

for(int q=0;q<max+1;q++)
{
mooc[q]=mooc[q+1];
}
max--;
x++;
}
if(mooc[p]!=0)
bl=0;
}
for(int p=0,x=0,bl=1;p<max+1;p++)
{
if(mooc[0]!=0)
bl=0;
if(bl==1)
{

for(int q=0;q<max+1;q++)
{
mooc[q]=mooc[q+1];
}
max--;
x++;
}
if(mooc[p]!=0)
bl=0;
}
if(bl==1)
{
for(int p=0;p<max+1;p++)
{
printf("%d",mooc[p]);
}
}
else
{
putchar('-');
for(int p=0;p<max+1;p++)
{
printf("%d",mooc[p]);
}
}
putchar('\n');
N:
;
}
return 0;
}

2024.05.05 猜数字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <string.h>
char baka[6][33]={{1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,0},{2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31,34,35,38,39,42,43,46,47,50,51,54,55,58,59,62,63,0},{4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31,36,37,38,39,44,45,46,47,52,53,54,55,60,61,62,63,0},{8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31,40,41,42,43,44,45,46,47,56,57,58,59,60,61,62,63,0},{16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0},{32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0}};
int busu[1000]={0};
int main (void)
{
int p=0,i=0;
for(int n=0;;n++)
{
scanf("%d",&busu[n]);
if(busu[n]==0)
break;
i=busu[n]-1;
baka[i][32]=9;
//printf("%d\n",baka[i][32]);
//printf("%d\n",busu[n]);
}

for(int n=0;;n++)
{
if(busu[n]==0)
break;
p=busu[n]-1;
for(int x=0;x<6;x++)
{

if(baka[x][32]!=9)
{
for(int m=0;m<32;m++)
{
for(int y=0;y<32;y++)
{
if(baka[p][y]==baka[x][m])
baka[p][y]=0;
}
}
}
}/*
for(int y=0;y<32;y++)
{
printf("%d,",(baka[p][y]));
}
putchar('\n');*/
}
for(int x=0;x<6;x++)
{
if(baka[x][32]!=9)
{
memset(baka[x],0,32);
}
}
for(int n=0;;n++)
{
if(busu[n]==0)
break;
p=busu[n]-1;
for(int x=0;x<6;x++)
{
if(busu[1]!=0)
{
if(baka[x][32]==9&&x!=p)
{
for(int m=0;m<32;m++)
{
for(int y=0;y<32;y++)
{
if(baka[p][y]==baka[x][m]&&baka[p][y]!=0)
{
printf("%d\n",baka[p][y]);
return 0;
}
}
}
}
}
else
{
if(baka[x][32]==9)
{
for(int m=0;m<32;m++)
{
for(int y=0;y<32;y++)
{
if(baka[p][y]==baka[x][m]&&baka[p][y]!=0)
{
printf("%d\n",baka[p][y]);
return 0;
}
}
}
}
}
}/*
for(int y=0;y<32;y++)
{
printf("%d,",(baka[p][y]));
}
putchar('\n');*/
}
}

2024.05.11 对一个整数数组排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int resort(int *pa[],int num);

int main(int argc, char *argv[]) {

int a[100];
int num;

int *pa[100];
scanf("%d",&num);

int i=0;
for(i=0;i<num;i++)
{
scanf("%d",&a[i]);
pa[i]=&a[i];
}

resort(pa,num);

for(i=0;i<num;i++)
{
printf("%d\n",*pa[i]);
}




return 0;
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
int resort(int *pa[],int num)
{
for(int m=0,q=0;m<num;m++)
{
for(q=0;q<num-m-1;q++)
{
if(*pa[q+1]<*pa[q])
{
int *a=pa[q];
pa[q]=pa[q+1];
pa[q+1]=a;
}
}
}
return 0;
}

2024.05.11 二维数组排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <stdlib.h>

#define ROW 3
#define COL 4


/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int resort(int (*pa)[COL],int row,int col);

int main(int argc, char *argv[]) {

int a[ROW][COL];
// int num;

int (*pa)[COL];

int i=0,j=0;
for(i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
scanf("%d",&a[i][j]);
}
pa=a;

resort(a,ROW,COL);

for(i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
printf("%3d",a[i][j]);
printf("\n");
}
return 0;
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
int resort(int (*pa)[COL],int row,int col)
{
for(int p=0;p<row;p++,pa++)
{
for(int m=0,q=0;m<col;m++)
{
for(q=0;q<col-m-1;q++)
{
if((*pa)[q+1]<(*pa)[q])
{
int a=(*pa)[q];
(*pa)[q]=(*pa)[q+1];
(*pa)[q+1]=a;
}
}
}
}
return 0;
}

2024.05.13 小蜜蜂/斐波那契数列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <string.h>
void cirno(int*,int*,int*);
void fib(int,int*);
int main(void)
{
int n0, n1;
scanf("%d %d", &n0, &n1);
int n = n1 - n0;
int result[100] = {0};
fib(n, result);
int start = 99;
while (start > 0 && result[start] == 0) start--;
for (int i = start; i >= 0; i--)
printf("%d", result[i]);
putchar('\n');
return 0;
}
void cirno(int *a, int *b, int *c)
{
int jinWei = 0;
for (int i = 0; i < 100; i++)
{
int sum = a[i] + b[i] + jinWei;
c[i] = sum % 10;
jinWei = sum / 10;
}
}
void fib(int n, int *result)
{
int a[100] = {0};
int b[100] = {0};
a[0] = 1;
b[0] = 1;
for (int i = 2; i <= n; i++)
{
int temp[100] = {0};
cirno(a, b, temp);
memcpy(a, b,400);
memcpy(b, temp,400);
}
memcpy(result, b, 400);
}

2024.05.13 数组排序/指针

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */


char *resort(char *a);
int main(int argc, char *argv[]) {

char a[100];
gets(a);
puts(resort(a));
return 0;
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
char *resort(char *a)
{
int p=0;
for(int m=0;m<strlen(a);m++)
{
for(int n=0;n<strlen(a)-m-1;n++)
{
if(a[n+1]<a[n])
{
p=a[n];
a[n]=a[n+1];
a[n+1]=p;
}
}
}
return a;
}

2024.05.20 三角形面积

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
int main(void)
{
int num=0;
scanf("%d",&num);
for(int numb=0;numb<num;numb++)
{
int n=0;
scanf("%d",&n);
int x[1000]={0},y[1000]={0};
float s=0.0;
for(int nu=0;nu<n;nu++)
scanf("%d %d",&x[nu],&y[nu]);
int a,b,c;
for(a=0;a<n-2;a++)
{
for(b=a+1;b<n-1;b++)
{
for(c=b+1;c<n;c++)
{
float sq=0.0;
sq=0.5*(x[a]*(y[b]-y[c])+x[b]*(y[c]-y[a])+x[c]*(y[a]-y[b]));
if(sq<0)
sq/=-1;
if(sq>=s)
s=sq;
}
}
}
printf("%.1f\n",s);
}
return 0;
}

2024.06.04 逆波兰运算

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
int operation(char ch,int *k)
{
switch (ch)
{
case '+':return(*k+*(k+1));
case '-':return(*k-*(k+1));
case '*':return(*k * *(k+1));
case '/':return(*k / *(k+1));
default:return 0;
}
}
int main(void)
{
int operation(char,int *);
static int number[50];
int i=0;
char sign[50],*p=sign;
gets(sign);
while(*p)
{
if(*p<'9'&&*p>='0')
number[i++]=atoi(p);
else
{
number[i-2]=operation(*p,&number[i-2]);
i--;
}
for(p++;!(*p!=' '&&*(p-1)==' ')&&*p;p++);
}
printf("%d\n",number[0]);
return 0;
}

2024.06.08 零一一零

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char baka[10000];
int cirno (char*p);
int tm=0,num=0,ct=0;
int main (void)
{
baka[0]='0';
baka[1]='\0';
scanf("%d %d",&tm,&num);
cirno(baka);
printf("%c\n",baka[num-1]);
}
int cirno (char*p)
{
ct++;
for(int n=0;n<strlen(baka);n++)
{

if(baka[n]=='0')
{
char* busu=(char*)malloc(1000);
strcpy(busu,baka+n+1);
n++;
baka[n]='1';
baka[n+1]='\0';
strcat(baka,busu);
free(busu);
continue;
}
if(baka[n]=='1')
{
char* busu=(char*)malloc(1000);
strcpy(busu,baka+n+1);
n++;
baka[n]='0';
baka[n+1]='\0';
strcat(baka,busu);
free(busu);
}
}
if(ct==tm)
return 0;
else
cirno(baka);
return 0;
}

字符串题

2024.05.11 计算子字符串个数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <string.h>
int countsub( char *str, char *ss );

int main(void)
{
char s1[1000] = {0}, s2[100] = {0};
gets(s1);
gets(s2);
printf("%d\n", countsub( s1, s2 ) );
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
int countsub( char *str, char *ss )
{
int m=0;
for(int n=0;n<strlen(str);n++)
{
char baka[1000]={0};
strcpy(baka,str);
baka[n+strlen(ss)]='\0';
if(strcmp((baka+n),ss)==0)
{
if(m!=0)
{
for(int p=0;p<strlen(ss);p++)
{
if(baka[n-1-p]!=ss[strlen(ss)-1-p])//strtok
goto N;
}
m++;
}
else
m++;
}
N:
;
}
return m;
}

2024.05.13 合并排序/指针

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int merge_sort(char *a,char *b,char *c);
int main(int argc, char *argv[]) {

char a[100];
char b[100];
char c[200];

gets(a);
gets(b);
merge_sort(a,b,c);
puts(c);
return 0;
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
int merge_sort(char *a,char *b,char *c)
{
char d[100];
strcpy(d,a);
strcpy(d+strlen(a),b);
int p=0;
//puts(d);
for(int m=0;m<strlen(d);m++)
{
for(int n=0;n<strlen(d)-m-1;n++)
{
if(d[n+1]<d[n])
{
p=d[n];
d[n]=d[n+1];
d[n+1]=p;
}
}
}
strcpy(c,d);
return 0;
}

2024.04.14 三段字符串查找填充

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <string.h>
int main(void)
{
char a[100]={0},b[100]={0},c[100]={0};
scanf("%s %s %s",a,b,c);
for(int n=0;n<strlen(a);n++)
{
int m;
for(m=0;m<strlen(b);m++)
{
if(a[n+m]!=b[0+m])
break;
}
if(m==strlen(b))
{
char d[100]={0};
strcpy(d,a+n+strlen(b));
strcpy(a+n,c);
strcpy(a+n+strlen(c),d);
}
}
printf("%s\n",a);
}

2024.05.08 消除元音

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <string.h>
int n =0;
int main(void)
{
scanf("%d",&n);
getchar();
for(int m=0;m<n;m++)
{
char baka[1000]={0};
scanf("%[^\n]",baka);
for(int p=0;p<strlen(baka);p++)
{
if(baka[p]=='a'||baka[p]=='o'||baka[p]=='e'||baka[p]=='u'||baka[p]=='i'||baka[p]=='A'||baka[p]=='O'||baka[p]=='E'||baka[p]=='U'||baka[p]=='I')
{
for(int q=p;q<strlen(baka);q++)
baka[q]=baka[q+1];
p--;
}
}
printf("%s\n",baka);
getchar();
}
}

2024.05.15 字符串查找/期中/注释损坏*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <string.h>
char baka[1000]={0};
char busu[1000][1000]={0};
int ct=0,p=0,q=0;
int main(void)
{
int m=0,n=0;
scanf("%s",baka);
//if(scanf(""))
for(n=2;n<strlen(baka);n++)
{
for(m=0;m+q+p<strlen(baka);m++)
{
int bl=1;
for(q=n;q<strlen(baka);q++)
{
for(p=0;p<n;p++)
{
if(baka[m+p]!=baka[m+q+p])
break;
}
if(p==n)
{
bl++;
q=q+n-1;
}
}
if(bl!=0&&bl!=1)
busu[n][m]+=bl;
q=0;p=0;
}
}
int bol=1,max=0,u1=0,w1=0;
for(int u=(int)strlen(baka);u>=2;u--)
{
for(int w=0;w<strlen(baka);w++)
{
if(busu[u][w]!=0)
{
if(busu[u][w]>max)
{
max=busu[u][w];u1=u;w1=w;
}
bol=0;
}
}
}
//濡傝璋冭瘯鎶婅繖閮ㄥ垎娉ㄩ噴鎺?
baka[w1+u1]='\0';
if(bol==1)
printf("no result!\n");
else
printf("%s %d times\n",baka+w1,max);
//涓嬮潰鐨勬槸璋冭瘯鍧愭爣
/*
for(int u=2;u<(strlen(baka));u++)
{
for(int w=0;w<strlen(baka);w++)
{
printf("%d",busu[u][w]);
}
printf("\n");
}*/
}

应用题

2024.04.15 BOSS/注释损坏了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include <stdio.h>
char Nb(char);
char noob[100];
char nob[100];
char mooc[100];
char moc[100];
int bl=1;
int main (void)
{
scanf("%s %s %s",noob,noob+2,noob+4);
scanf("%s %s %s",mooc,mooc+2,mooc+4);

if(Nb(noob[0])<Nb(noob[2]))
{
if(Nb(noob[2])<Nb(noob[4]))
{
nob[0]=noob[4];
nob[1]=noob[5];
nob[2]=noob[2];
nob[3]=noob[3];
nob[4]=noob[0];
nob[5]=noob[1];
}
else
{
if(Nb(noob[4])>Nb(noob[0]))
{
nob[0]=noob[2];
nob[1]=noob[3];
nob[2]=noob[4];
nob[3]=noob[5];
nob[4]=noob[0];
nob[5]=noob[1];
}
else if(Nb(noob[4])<=Nb(noob[0]))
{
nob[0]=noob[2];
nob[1]=noob[3];
nob[2]=noob[0];
nob[3]=noob[1];
nob[4]=noob[4];
nob[5]=noob[5];
}
}
}
else
{
if(Nb(noob[2])>Nb(noob[4]))
{
nob[0]=noob[0];
nob[1]=noob[1];
nob[2]=noob[2];
nob[3]=noob[3];
nob[4]=noob[4];
nob[5]=noob[5];
}
else
{
if(Nb(noob[4])<Nb(noob[0]))
{
nob[0]=noob[0];
nob[1]=noob[1];
nob[2]=noob[4];
nob[3]=noob[5];
nob[4]=noob[2];
nob[5]=noob[3];
}
else
{
nob[0]=noob[4];
nob[1]=noob[5];
nob[2]=noob[2];
nob[3]=noob[3];
nob[4]=noob[0];
nob[5]=noob[1];
}
}
}
if(bl==1)
{
if(Nb(nob[0])==Nb(nob[2]))
{
if(Nb(nob[3])>Nb(nob[1]))
{
nob[99]=nob[1];
nob[1]=nob[3];
nob[3]=nob[99];
}
else if(Nb(nob[3])==Nb(nob[1]))
{
printf("Input Error!\n");
return 0;
}
}
else if(Nb(nob[2])==Nb(nob[4]))
{
if(Nb(nob[5])>Nb(nob[3]))
{
nob[99]=nob[3];
nob[3]=nob[5];
nob[5]=nob[99];
}
else if(Nb(nob[5])==Nb(nob[3]))
{
printf("Input Error!\n");
return 0;
}
}
}
else if(bl==0)
{
printf("Input Error!\n");
return 0;
}
if(Nb(mooc[0])<Nb(mooc[2]))
{
if(Nb(mooc[2])<Nb(mooc[4]))
{
moc[0]=mooc[4];
moc[1]=mooc[5];
moc[2]=mooc[2];
moc[3]=mooc[3];
moc[4]=mooc[0];
moc[5]=mooc[1];
}
else
{
if(Nb(mooc[4])>Nb(mooc[0]))
{
moc[0]=mooc[2];
moc[1]=mooc[3];
moc[2]=mooc[4];
moc[3]=mooc[5];
moc[4]=mooc[0];
moc[5]=mooc[1];
}
else if(Nb(mooc[4])<=Nb(mooc[0]))
{
moc[0]=mooc[2];
moc[1]=mooc[3];
moc[2]=mooc[0];
moc[3]=mooc[1];
moc[4]=mooc[4];
moc[5]=mooc[5];
}
}
}
else
{
if(Nb(mooc[2])>Nb(mooc[4]))
{
moc[0]=mooc[0];
moc[1]=mooc[1];
moc[2]=mooc[2];
moc[3]=mooc[3];
moc[4]=mooc[4];
moc[5]=mooc[5];
}
else
{
if(Nb(mooc[4])<Nb(mooc[0]))
{
moc[0]=mooc[0];
moc[1]=mooc[1];
moc[2]=mooc[4];
moc[3]=mooc[5];
moc[4]=mooc[2];
moc[5]=mooc[3];
}
else
{
moc[0]=mooc[4];
moc[1]=mooc[5];
moc[2]=mooc[2];
moc[3]=mooc[3];
moc[4]=mooc[0];
moc[5]=mooc[1];
}
}
}
if(bl==1)
{
if(Nb(moc[0])==Nb(moc[2]))
{
if(Nb(moc[3])>Nb(moc[1]))
{
moc[99]=moc[1];
moc[1]=moc[3];
moc[3]=moc[99];
}
else if(Nb(moc[3])==Nb(moc[1]))
{
printf("Input Error!\n");
return 0;
}
}
else if(Nb(moc[2])==Nb(moc[4]))
{
if(Nb(moc[5])>Nb(moc[3]))
{
moc[99]=moc[3];
moc[3]=moc[5];
moc[5]=moc[99];
}
else if(Nb(moc[5])==Nb(moc[3]))
{
NOOB:
printf("Input Error!\n");
return 0;
}
}
if(Nb(nob[0])>Nb(moc[0]))
{
printf("Winner is A!\n");
}
else if(Nb(nob[0])<Nb(moc[0]))
{
printf("Winner is B!\n");
}
else
{
if(Nb(nob[1])>Nb(moc[1]))
printf("Winner is A!\n");
else if(Nb(nob[1])<Nb(moc[1]))
printf("Winner is B!\n");
else
{
if(Nb(nob[5])>Nb(moc[5]))
{
printf("Winner is A!\n");
}
else if(Nb(nob[5])<Nb(moc[5]))
{
printf("Winner is B!\n");
}
else
printf("Winner is X!\n");
}
}
}
else if(bl==0)
{
printf("Input Error!\n");
return 0;
}
printf("A: %c%c %c%c %c%c\n",nob[0],nob[1],nob[2],nob[3],nob[4],nob[5]);
printf("B: %c%c %c%c %c%c\n",moc[0],moc[1],moc[2],moc[3],moc[4],moc[5]);
return 0;
}
char Nb(char ch)
{
switch(ch)
{
case 'H':
return 'D';
case 'S':
return 'C';
case 'D':
return 'B';
case 'C':
return 'A';
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case '10':
return 10;
case 'J':
return 11;
case 'Q':
return 12;
case 'K':
return 13;
case 'A':
return 14;
default:
{
bl=0;
return 0;
}
}
}

2024.04.16 BOSS PRO

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char baka[6][10];
char *p[6]={baka[0],baka[1],baka[2],baka[3],baka[4],baka[5]};
int bl=1;
char Cirno (char);
int Mystia (char*);
void Daichan (int);
void Rumia (int);
int Wriggle(int);
int Marisa(int);
int main(void)
{
scanf("%s%s%s%s%s%s",baka[0],baka[1],baka[2],baka[3],baka[4],baka[5]);
//Marisa(3);
Marisa(6);
Daichan (3);
Rumia (3);
//putchar('\n');
Daichan (6);
Rumia (6);
if(bl==1)
{
if(Wriggle(3)<Wriggle(6))
printf("Winner is B!\n");
else if(Wriggle(3)>Wriggle(6))
printf("Winner is A!\n");
else
{
if(Cirno(p[0][0])>Cirno(p[3][0]))
printf("Winner is A!\n");
else if(Cirno(p[0][0])<Cirno(p[3][0]))
printf("Winner is B!\n");
else
{
if(Mystia(p[0]+1)>Mystia(p[3]+1))
printf("Winner is A!\n");
else if(Mystia(p[0]+1)<Mystia(p[3]+1))
printf("Winner is B!\n");
else
{
if(Cirno(p[1][0])>Cirno(p[4][0]))
printf("Winner is A!\n");
else if(Cirno(p[1][0])<Cirno(p[4][0]))
printf("Winner is B!\n");
else
{
if(Mystia(p[1]+1)>Mystia(p[4]+1))
printf("Winner is A!\n");
else if(Mystia(p[1]+1)<Mystia(p[4]+1))
printf("Winner is B!\n");
else
{
if(Cirno(p[2][0])>Cirno(p[5][0]))
printf("Winner is A!\n");
else if(Cirno(p[2][0])<Cirno(p[5][0]))
printf("Winner is B!\n");
else
{
if(Mystia(p[2]+1)>Mystia(p[5]+1))
printf("Winner is A!\n");
else if(Mystia(p[2]+1)<Mystia(p[5]+1))
printf("Winner is B!\n");
else
printf("Draw!\n");
}
}
}
}
}
}
printf("A: %s %s %s\n",p[0],p[1],p[2]);
printf("B: %s %s %s\n",p[3],p[4],p[5]);
}
else
printf("Input Error!\n");
return 0;
}
char Cirno (char q)//杞崲sz澶у皬
{
switch(q)
{
case 'H':return 'D';
case 'S':return 'C';
case 'D':return 'B';
case 'C':return 'A';
default:bl=0;return q;
}
}
int Mystia (char* x)//杞寲JQKA澶у皬
{
int v=atoi(x);
if(v!=0)
{
switch(v)
{
case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:return v;
default:bl=0;return v;
}
}
else
{
int w=(int)x[0];
switch(w)
{
case 74:return 11;
case 81:return 12;
case 75:return 13;
case 65:return 14;
default:bl=0;return v;
}
}
}
void Daichan (int z)//鎺掑垪zm椤哄簭
{
int i,j;
for(i=z-3;i<z;i++)
{
for(j=i+1;j<z;j++)
{
if(Mystia(p[i]+1)<Mystia(p[j]+1))
{
//putchar('?');
char *r;
r=p[i];
p[i]=p[j];
p[j]=r;
}
}
//printf("%s ",p[i]);
}
}
void Rumia (int y)//鎺掑垪zm椤哄簭
{
int k,l;
k=0;
for(k=y-3;k<y;k++)
{
for(l=k+1;l<y;l++)
{
if(Mystia(p[k]+1)==Mystia(p[l]+1))
{
if(Cirno(p[k][0])<Cirno(p[l][0]))
{
char *t;
t=p[k];
p[k]=p[l];
p[l]=t;
}
}
}
//printf("%s ",p[k]);
}
}
int Wriggle(int num)//鍒ゆ柇浼樺厛绾?
{
int first=Mystia(p[num-3]+1);
int second=Mystia(p[num-2]+1);
int third=Mystia(p[num-1]+1);
//printf("%d %d %d\n",first,second,third);
if((p[num-3][0]==p[num-2][0])&&(p[num-2][0]==p[num-1][0]))
{
if ((first + 1 == second && second + 1 == third) || (first - 1 == second && second - 1 == third))
{
//printf("鍚岃姳椤篭n");
return 5;
}
}
else if((first==second)&&(second==third))
{
//printf("鐐稿脊\n");
return 4;
}
else if ((first + 1 == second && second + 1 == third) || (first - 1 == second && second - 1 == third))
{
//printf("杩炵墝\n");
return 3;
}
else if((first==second)||(first==third)||(second==third))
{
//printf("瀵瑰瓙\n");
return 2;
}
else
{
return 1;
}
return 0;
}
int Marisa(int u)//鍒ゆ柇鏄惁閲嶇墝
{
for(int r=0;r<3;r++)
{
for(int t=1;(r+t)<3;t++)
{
//printf("%s %s\n",p[r],p[r+t]);
if(strcmp(p[r],p[r+t])==0)
{
//printf("瀵瑰瓙\n");
//printf("%s %s\n",p[r],p[r+t]);
bl=0;
}
}
}
//printf("%s %s\n",p[3],p[4]);
for(int r=3;r<6;r++)
{
for(int t=1;(r+t)<6;t++)
{
//putchar('?');
//printf("%s %s\n",p[r],p[r+t]);
if(strcmp(p[r],p[r+t])==0)
{
//printf("瀵瑰瓙\n");
//printf("%s %s\n",p[r],p[r+t]);
bl=0;
}
}
}
return 0;
}

2024.04.23 水王争霸/注释损坏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <string.h>
int n=0;
char baka[1000][10000]={0};
char busu[1000][10000]={0};
char *p[1000]={0};
char *y[1000]={0};
int main(void)
{
int i=0,j=0;
scanf("%d",&n);//杈撳叆浜烘暟
for(int m=0;m<n;m++)
{

scanf("%s %s",baka[m],busu[m]);//杈撳叆浜哄悕锛屾暟閲?
p[m]=busu[m];
y[m]=baka[m];
}
for(i=0;i<n;i++)//鍒ゆ柇鏁伴噺闀跨煭
{
for(j=i+1;j<n;j++)
{
if(strlen(p[i])<strlen(p[j]))
{
//putchar('?');
char*q;
q=p[i];
p[i]=p[j];
p[j]=q;
char*x;
x=y[i];
y[i]=y[j];
y[j]=x;
}
}
//printf("%s %s\n",y[i],p[i]);
}
for(i=0;i<n;i++)//鍒ゆ柇澶у皬
{
for(j=i+1;j<n;j++)
{
if(strlen(p[i])-strlen(p[j])==0)//濡傛灉涓や釜闀垮害鐩稿悓
{
for(int m=0;m<strlen(p[i]);m++)
{
if(p[i][m]-p[j][m]<0)//浣嶆暟姣斿ぇ灏?
{
//putchar('?');
char*q;
q=p[i];
p[i]=p[j];
p[j]=q;
char*x;
x=y[i];
y[i]=y[j];
y[j]=x;
break;
}
else if(p[i][m]-p[j][m]>0)
break;
}
if(strcmp(p[i],p[j])==0)
{
for(int m=0;m<strlen(y[i]);m++)
{
if(y[i][m]>y[j][m])
{
//putchar('!');
char*q;
q=p[i];
p[i]=p[j];
p[j]=q;
char*x;
x=y[i];
y[i]=y[j];
y[j]=x;
break;
}
else if(y[i][m]-y[j][m]<0)
break;
}

}
}
//noob:
//;
}
printf("%s\n",y[i]);
}
return 0;
}

2024.04.29 通用产品代码校验位

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
int a,b,c;
int main(void)
{
scanf("%d %d %d",&a,&b,&c);
int j,o,all;
j=3*(a+(b/1000%10)+(b/10%10)+(c/10000%10)+(c/100%10)+(c%10));
o=(b/10000%10+b/100%10+b%10+c/1000%10+c/10%10);
//printf("%d %d",j,o);
all=9-((j+o-1)%10);
printf("%d\n",all);
return 0;
}

2024.04.29 五年级小学生的题目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
int cirno(int,int,char);
char noob (void);
int main (void)
{
static int baka=0,max=-1000,min=1000;
static char ch=0/*,benDan=0*/;
while(scanf("%d",&baka)==1)
{
getchar();
if(baka>max)
max=baka;
if(baka<min)
min=baka;
}
ch=noob();

if(min>=0)
printf("%d %c %d = %d\n",max,ch,min,cirno(max,min,ch));
else if(min==0&&ch=='/')
printf("Error!\n");
else
printf("%d %c (%d) = %d\n",max,ch,min,cirno(max,min,ch));
return 0;
}
int cirno(int ma,int mi,char c)
{
switch(c)
{
case '+':return ma+mi;
case '-':return ma-mi;
case '*':return ma*mi;
case '/':return ma/mi;
case '%':return ma%mi;
}
return 0;
}
char noob(void)
{
char busu;
scanf("%c",&busu);
return busu;
}

2024.05.02 大家一起做游戏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
int kid =0;
int num =0;
int noob[1000];
int main(void)
{
scanf("%d %d",&kid,&num);
int k=kid;
int m=1,n;
if(num==1)
{
printf("The left child is NO %d.\n",kid);
return 0;
}
while(k>1)
{
for(n=0;n<kid;n++)
{
if(noob[n]!='0')
{
if(m==num)
{
m=0;
k--;
}
noob[n]=m+48;
m++;
}
}
}
for(int p=0;p<kid;p++)
{
if(noob[p]!='0')
printf("The left child is NO %d.\n",p+1);
}
return 0;
}

2024.05.05 扫雷

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
int main(void)
{
int num=0;
scanf("%d",&num);
for(int numb=0;numb<num;numb++)
{
int n=0;
scanf("%d",&n);
int x[1000]={0},y[1000]={0};
float s=0.0;
for(int nu=0;nu<n;nu++)
scanf("%d %d",&x[nu],&y[nu]);
int a,b,c;
for(a=0;a<n-2;a++)
{
for(b=a+1;b<n-1;b++)
{
for(c=b+1;c<n;c++)
{
float sq=0.0;
sq=0.5*(x[a]*(y[b]-y[c])+x[b]*(y[c]-y[a])+x[c]*(y[a]-y[b]));
if(sq<0)
sq/=-1;
if(sq>=s)
s=sq;
}
}
}
printf("%.1f\n",s);
}
return 0;
}

2024.05.05 身份证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <string.h>
char calculateCheckCode(const char *id) {
int baka[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char checkCodes[11] = "10X98765432";
int sum = 0;
for (int i = 0; i < 17; i++) {
sum += (id[i] - '0') * baka[i];
}
int mod = sum % 11;
return checkCodes[mod];
}
void upgradeID(char *id) {
char newID[19];
strncpy(newID, id, 6);
newID[6] = '1';
newID[7] = '9';
strncpy(newID + 8, id + 6, 9);
newID[17] = calculateCheckCode(newID);
newID[18] = '\0';
strcpy(id, newID);
}
int validateID(const char *id) {
if (strlen(id) == 15) {
char newID[19];
strcpy(newID, id);
upgradeID(newID);
printf("%s\n", newID);
} else if (strlen(id) == 18) {
int sum = 0;
for (int i = 0; i < 17; i++) {
if (id[i] < '0' || id[i] > '9') {
return 0;
}
sum += (id[i] - '0') * (1 << (17 - i));
}
char checkCode = calculateCheckCode(id);
if (id[17] == checkCode) {
printf("Valid\n");
} else {
printf("Invalid\n");
}
} else {
printf("Invalid\n");
}
return 1;
}
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char id[19];
scanf("%s", id);
validateID(id);
}
return 0;
}

2024.05.08 铺地板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#define MAX 100
int main(void)
{
int n, arr[MAX][MAX];
scanf ("%d", &n);
int x = 1, y = 1;
int num=1;
int bl=1; for(;num<=n*n;)
{
if(n%2==1)
{
if(x==1&&y==n)
bl=0;
else
bl=1;
}
if((y==1||y==n)&&x!=n&&bl==1)
{
arr[x][y]=num;
x++;
num++;
}
if((x+y)%2==1)
{
arr[x][y]=num;
x--;
y++;
num++;
}
if((x+y)%2==0)
{
arr[x][y]=num;
x++;
y--;
num++;
}
if((x==1||x==n)&&y!=n)
{
arr[x][y]=num;
y++;
num++;
}
}
for (y = 1; y <= n; y++)
{
for (x = 1; x <= n; x++)
{
if (x == 1)
{
if(n<14)
printf("%2d", arr[x][y]);
else
printf("%3d", arr[x][y]);
}
else
{
if(n*n<100)
printf("%3d", arr[x][y]);
else
printf("%4d", arr[x][y]);
}
}
printf("\n");
}
return 0;
}

2024.05.27 撞球+

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <strings.h>
#include <math.h>
float X=0,Y=0;
float Sx=0,Sy=0;
float Ex=0,Ey=0;
char way[1000];
int main(void)
{
scanf("%f %f",&X,&Y);
scanf("%f %f",&Sx,&Sy);
scanf("%f %f",&Ex,&Ey);
scanf("%s",way);
for(int n=0;n<strlen(way);n++)
{
switch(way[n])
{
case 'F':Sy/=-1;break;
case 'B':Sy=2*Y-Sy;break;
case 'L':Sx/=-1;break;
case 'R':Sx=2*X-Sx;break;
}
}
printf("%.4f\n",sqrt(pow(Sx-Ex,2)+pow(Ey-Sy,2)));
}

2024.06.09 渣渣的程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <string.h>
void Suojin(void);
int cirno(char* );
int bol=1;
int left=0,right=0;
char baka[10000]={0};
int main (void)
{
while(left>right||left==0||bol==1)
{
memset(baka,0,10000);
scanf("%[^\n]",baka);
getchar();
cirno(baka);
}
}
void Suojin(void)
{
for(int q=0;q<(left-right);q++)
printf(" ");
}
int cirno(char* busu)
{
int bl=1;
if(busu[0]=='\0')
return 0;
for(int n=0;n<strlen(busu);n++)
{
char mooc[10000]={0};
if((busu[n]=='m')&&(busu[n+1]=='a')&&(busu[n+2]=='i')&&(busu[n+3]=='n'))
{
left=0;
right=0;
bol=0;
}
if(busu[n]=='(')
bl=0;
if(busu[n]==')')
bl=1;
if(bl==1)
{
if(busu[n]=='{')
{
strcpy(mooc,busu+n+1);
busu[n]='\0';
if(busu[0]!='\0')
{
Suojin();
printf("%s\n",busu);
}
Suojin();
printf("{\n");
left++;
cirno(mooc);
return 0;
}
else if(busu[n]=='}')
{
strcpy(mooc,busu+n+1);
busu[n]='\0';
if(busu[0]!='\0')
{
Suojin();
printf("%s\n",busu);
}
right++;
Suojin();
printf("}\n");
cirno(mooc);
return 0;
}
else if(busu[n]==';')
{
strcpy(mooc,busu+n+1);
busu[n+1]='\0';
if(busu[0]!='\0')
{
Suojin();
printf("%s\n",busu);
}
cirno(mooc);
return 0;
}
}
}
Suojin();
printf("%s\n",busu);
return 0;
}

2024.05.15 机动车尾号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
int main (void)
{
int y,m,d;
int i=0;
scanf("%d %d %d",&y,&m,&d);
for(int n=y-1;n>=2012;n--)
{
if((n%4==0&&n%100!=0)||n%400==0)
i+=2;
else
i++;
}
printf("%d\n",i);
}

2024.05.19 机智的大师

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
int main (void)
{
int num=0,rp=0,min=100000,mi=-1;
scanf("%d %d",&num,&rp);
int baka[num];
for(int n=0;n<num;n++)
scanf("%d",&baka[n]);
for(int m=0;m<num;m++)
{
mi=-1;min=100000;
for(int n=0;n<num;n++)
if(baka[n]-rp<=min&&baka[n]-rp>=0)
{
min=baka[n]-rp;
mi=n;
}
if(mi>=0)
{
rp+=2;
baka[mi]=0;
}
else
{
for(int p=0;p<num;p++)
if(baka[p]!=0)
{
rp++;
baka[p]=0;
break;
}
}
}
printf("%d\n",rp);
}

2024.05.20 爱刷题的大神/注释损坏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*ORZ Cirno BaKa*/
#include <stdio.h>
#include <string.h>
typedef struct cirno
{
int nu,sc;
}MAN;
void quick_sort(MAN noob[100], int l, int r);
int main(void)
{
char file[100];
scanf("%s",file);
FILE *fp=NULL;
fp = fopen(file,"r");
int num=0;
fscanf(fp,"%d",&num);
for(int n=0;n<num;n++)
{
int qiz=0;
fscanf(fp,"%d",&qiz);
struct cirno baka[100];
for(int q=0;q<qiz;q++)
fscanf(fp,"%d %d",&baka[q].nu,&baka[q].sc);
int q;
for(q=0;q<qiz;q++)
if(baka[q].sc>=100)
break;
if(q==qiz)
{
printf("This OJ is too easy for PQ Dashen!\n");
continue;
}
quick_sort(baka,0,qiz);
for(q=0;q<qiz;q++)
printf("%d\n",baka[q].nu);

if(n<num-1)
printf("\n");
}
fclose(fp);
}
//蹇€熸帓搴?
void quick_sort(MAN noob[100], int l, int r)
{
if (l < r)
{
//Swap(s[l], s[(l + r) / 2]); //灏嗕腑闂寸殑杩欎釜鏁板拰绗竴涓暟浜ゆ崲 鍙傝娉?
int i = l, j = r, x = noob[l].sc;
while (i < j)
{
while(i < j && noob[j].sc >= x) // 浠庡彸鍚戝乏鎵剧涓€涓皬浜巟鐨勬暟
j--;
if(i < j)
noob[i++].sc = noob[j].sc;

while(i < j && noob[i].sc < x) // 浠庡乏鍚戝彸鎵剧涓€涓ぇ浜庣瓑浜巟鐨勬暟
i++;
if(i < j)
noob[j--].sc = noob[i].sc;
}
noob[i].sc = x;
quick_sort(noob, l, i - 1); // 閫掑綊璋冪敤
quick_sort(noob, i + 1, r);
}
}

2024.05.20 不高兴的女朋友/520限定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
int main (void)
{
struct cirno
{
int w,s;
};
struct cirno baka[7];
for(int n=0;n<7;n++)
scanf("%d %d",&baka[n].w,&baka[n].s);
int max,m,d=0;
for(m=0,max=0;m<7;m++)
{
if((baka[m].w)+(baka[m].s)>max)
{
d=m;
max=(baka[m].w)+(baka[m].s);
}
if(max<10)
d=-1;
}
printf("%d\n",d+1);
}

2024.05.27 学生成绩排行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <string.h>
int main (void)
{
struct cirno
{
char name[1000];
int sc;
};
struct cirno baka[1000];
int num=0;
scanf("%d",&num);
getchar();
for(int n=0;n<num;n++)
{
scanf("%[^,],%d",baka[n].name,&baka[n].sc);
getchar();
}
for(int i=0;i<num;i++)
for(int j=0;j<num-1-i;j++)
if(baka[j].sc<baka[j+1].sc)
{
struct cirno temp = baka[j];
baka[j] = baka[j + 1];
baka[j + 1] = temp;
}
for(int q=0;q<num;q++)
printf("%s,%d\n",baka[q].name,baka[q].sc);
//putchar('\n');
}

2024.05.27 恭喜发财

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <string.h>
int main(void)
{
int num=0;
scanf("%d",&num);
struct cirno
{
char name[100];
int mo,give,gi;
char giname[100][100];
};
struct cirno baka[num];
for(int n=0;n<num;n++)
scanf("%s",baka[n].name);
for(int n=0;n<num;n++)
{
char na[100];
int p=0;
scanf("%s",na);
for(int m=0;m<num;m++)
if(strcmp(na,baka[m].name)==0)
{
p=m;
break;
}
scanf("%d %d",&baka[p].mo,&baka[p].give);
for(int t=0;t<baka[p].give;t++)
scanf("%s",baka[p].giname[t]);
}

for(int n=0;n<num;n++)
{
if(baka[n].give!=0)
baka[n].gi=baka[n].mo/baka[n].give;
else
baka[n].gi=0;
baka[n].mo=0;
}
for(int n=0;n<num;n++)
{
for (int q=0;q<baka[n].give;q++)
{
int p=0;
for(int m=0;m<num;m++)
if(strcmp(baka[n].giname[q],baka[m].name)==0)
{
p=m;
break;
}
baka[p].mo+=baka[n].gi;
//baka[n].mo-=baka[n].gi;
}
}
for(int q=0;q<num;q++)
printf("%s %d\n",baka[q].name,baka[q].mo-(baka[q].give*baka[q].gi));
}

2024.05.28 拱猪计分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
typedef struct cirno{
int num;
char card[1000][10];
}MAN;
int bl=0;
struct cirno baka[4];
int rumia (MAN);
int main (void)
{
while(!bl)
{
for(int n=0,bl=0;n<4;n++)
{
scanf("%d",&baka[n].num);
if(baka[n].num==0)
bl++;
if(bl==4)
return 0;
for(int m=0;m<baka[n].num;m++)
scanf("%s",baka[n].card[m]);
}
for(int n=0;n<4;n++)
{
if(rumia(baka[n])>0)
printf("+%d",rumia(baka[n]));
else
printf("%d",rumia(baka[n]));
if(n<3)
printf(" ");
}
printf("\n");
}
}
int rumia (MAN noob)
{
int red=0,bei=0,zhu=0,yag=0;
int sc=0,b=1;
for(int n=0;n<noob.num;n++)
{
if(noob.card[n][0]=='H')
red++;
if(noob.card[n][0]=='C'&&noob.card[n][1]=='1'&&noob.card[n][2]=='0')
bei++;
if(noob.card[n][0]=='D'&&noob.card[n][1]=='1'&&noob.card[n][2]=='1')
yag++;
if(noob.card[n][0]=='S'&&noob.card[n][1]=='1'&&noob.card[n][2]=='2')
zhu++;
}
if(red==0&&zhu==0&&yag==0&bei==0)
return 0;
if(red==0&&zhu==0&&yag==0&bei==1)
return 50;
if(zhu==1&&yag==1&&red==13)
sc+=500;
else if(red==13)
sc+=200;
else
{
for(int n=0;n<noob.num;n++)
{
if(noob.card[n][0]=='H')
{
if(noob.card[n][2]=='\0')
{
switch (noob.card[n][1])
{
case '1':sc-=50;break;
case '2':sc-=2;break;
case '3':sc-=3;break;
case '4':sc-=4;break;
case '5':sc-=5;break;
case '6':sc-=6;break;
case '7':sc-=7;break;
case '8':sc-=8;break;
case '9':sc-=9;break;
}
}
else
{
switch (noob.card[n][2])
{
case '0':sc-=10;break;
case '1':sc-=20;break;
case '2':sc-=30;break;
case '3':sc-=40;break;
}
}
}
}
}
if(zhu==1)
sc-=100;
if(yag==1)
sc+=100;
if(bei==1)
b=2;
return sc*b;
}

2024.05.28 数码管

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <string.h>
int cirno(char*);
int main(void)
{
while(1)
{
char baka[100]={0};
scanf("%s",baka);
if(baka[0]=='0')
return 0;
for(int n=0;n<5;n++)
{
if(baka[n]=='\0')
{
char emp[100]={"0"};
strcat(emp,baka);
strcpy(baka,emp);
}
}
cirno(baka);
printf("\n");
}
}
int cirno(char*noob)
{
for(int n=0;n<5;n++)
{
int num=0;
switch (noob[n])
{
case '1':num=0x50;break;
case '2':num=0x37;break;//24150//00110111/
case '3':num=0x57;break;
case '4':num=0x5A;break;//1346/01011010
case '5':num=0x4F;break;//01236/01001111
case '6':num=0x6F;break;
case '7':num=0x54;break;
case '8':num=0x7F;break;
case '9':num=0x5F;break;//01011111
case '0':num=0x7D;break;
}
if(n<4)
printf("%X ",num);
else
printf("%X",num);
}
return 0;
}

2024.06.11 安全的密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <string.h>
int cirno (char*);
int main(void)
{
int num;
scanf("%d",&num);
getchar();
while(num-->0)
{
char baka[100]={0};
gets(baka);
if(strlen(baka)<6)
printf("Not Safe\n");
else
cirno(baka);
}
return 0;
}
int cirno (char* busu)
{
int nu=0,en=0,es=0,caps=0;
for(int n=0;n<strlen(busu);n++)
{
if((busu[n]>='!'&&busu[n]<='/')||(busu[n]>=':'&&busu[n]<='@')||(busu[n]>='['&&busu[n]<='`')||(busu[n]==' '))
es=1;
else if(busu[n]>='0'&&busu[n]<='9')
nu=1;
else if(busu[n]>='a'&&busu[n]<='z')
en=1;
else if((busu[n]>='A'&&busu[n]<='Z'))
caps=1;
}
//printf("%d %d %d\n",nu,en,es);
if(nu+en+es+caps==1)
printf("Not Safe\n");
else if(nu+en+es+caps==2)
printf("Medium Safe\n");
else if(nu+en+es+caps>=3)
printf("Safe\n");
return 0;
}

2024.06.11 全能的战士

1
2
3
4
5
6
7
#include<stdio.h>
int main(void){
int n,n1,n2,n3,n12,n13,n23;
scanf("%d %d %d %d %d %d %d",&n,&n1,&n2,&n3,&n12,&n13,&n23);
printf("%d\n",n-(n1+n2+n3-n12-n13-n23));
return 0;
}

2024.06.12 凯撒密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int change (char*);
int seed (int);
int sort (int*,int);
char* outPut(char*,int);
int main (void)
{
char Rome[1000];
char Txt[10000];
int Num[25];
scanf("%s",Rome);
for(int p=0;p<25;p++)
scanf("%d",&Num[p]);
int key=sort(Num,seed(change(Rome)));
getchar();
gets(Txt);
puts(outPut(Txt,key));
}
int change (char* str)
{
int pst=0,now=0,tmp,tot=0;
for(int n=0;n<strlen(str);n++)
{
switch(str[n])
{
case 'I':now=1;break;
case 'V':now=5;break;
case 'X':now=10;break;
case 'L':now=50;break;
case 'C':now=100;break;
case 'D':now=500;break;
case 'M':now=1000;break;
default:break;
}
tmp=now;
if(pst<now&&pst!=0)
now=now-2*pst;
pst=tmp;
tot+=now;
}
return tot;
}
int seed (int s)
{
while(1)
{
int sed=0;
for(int n=1;;n*=10)
{
if(s%n==s)
break;
sed+=s/n%10;
}
s=sed;
if(sed%10==sed)
return sed;
}
}
int sort (int* it,int sed)
{
for(int i=0;i<25;i++)
{
for(int j=0;j<25-i-1;j++)
{
if(it[j]>it[j+1])
{
int tmp=it[j];
it[j]=it[j+1];
it[j+1]=tmp;
}
}
}
return it[sed-1];
}
char* outPut(char* txt,int key)
{
int swch=key%26;
printf("%d\n",swch);
for(int n=0;n<strlen(txt);n++)
{
if(txt[n]>='a'&&txt[n]<='z')
{
if((int)txt[n]+swch>122)
txt[n]+=(swch-26);
else
txt[n]+=swch;
}
}
return txt;
}

2024.06.13 最短路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
int main(void)
{
int x1,y1;
int x2,y2;
scanf("%d %d %d %d",&x2,&y2,&x1,&y1);
if(x1==0&&x2==0&&y1==0&&y2==0)
{
printf("1\n(0,0)\n");
return 0;
}
int fst=0,sec=0;
int mid1,mid2;
mid1=(x1-1)*(y1-1);
mid2=(x2-x1-1)*(y2-y1-1);
if(mid2<0)
mid2/=-1;
fst=x1*y1;
sec=(x2-x1)*(y2-y1);
if(sec<0)
sec/=-1;
printf("%d\n",(fst+1+mid1)*(sec+1+mid2));
int x=0,y=0;
for(int n=0;;n++)
{
if(x==x1&&y==y1)
break;
printf("(%d,%d)",x,y);
if(x==x1)
y++;
else
x++;
}
x=x1,y=y1;
for(int n=0;;n++)
{
printf("(%d,%d)",x,y);
if(x==x2&&y==y2)
break;
if(x==x2)
y++;
else
x++;
}
printf("\n");
return 0;
}

2024.06.25 大家一起做游戏/小学生

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node
{
char busu[6];
struct node * next;
} NODE;

NODE * head;
NODE * end;
NODE * mid;
void import (char *);
void subtract (int);
int main (void)
{
int n;
scanf("%d",&n);
int baka[n];
for(int m=0;m<n;m++)
scanf("%d",&baka[m]);
mid = (NODE *)malloc( sizeof(NODE) );
mid->next = NULL;
strcpy(mid->busu,"eijuy");

head = (NODE *)malloc( sizeof(NODE) );
head->next = mid;
strcpy(head->busu,"-1");

for(int p=0;p<n;p++)
{
char name[100];
scanf("%s",name);
import(name);
}

end = (NODE *)malloc( sizeof(NODE) );
head->next->next=end;
end->next = NULL;
strcpy(end->busu,"vrqfb");

for(int q=0;q<n;q++)
{
int flag=0;
if(q!=0)
{
for(int x=q;x>=0;x--)
if(baka[x]<baka[q])
flag++;
subtract(baka[q]-flag);
}
else
subtract(baka[0]);
}
}
void import (char *name)
{
while(head->next!=NULL)
head=head->next;
NODE* p=(NODE*)malloc(sizeof(NODE));
strcpy(p->busu,name);
p->next=NULL;
head->next=p;
return 0;
}
void subtract (int baka)
{
int count=0;
NODE * p;
NODE * q;
p=mid;
while(count<baka-1)
{
p = p->next;
count++;
}
q=p->next;
p->next=q->next;
printf("%s %s\n",p->busu,q->next->busu);
free(q);
return 0;
}

2024.06.25 开大招

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <string.h>//AWQEWAEQWQEE
int judge (char);
int count=1;
int Qcd=0,Wcd=0,Ecd=0,Acd=0;
char lst;
int main()
{
char skill[1000];
scanf("%s",skill);
lst=skill[0];
for(int n=1;n<strlen(skill);n++)
{
judge(skill[n]);
if(Qcd>0)
Qcd--;
if(Wcd>0)
Wcd--;
if(Ecd>0)
Ecd--;
if(Acd>0)
Acd--;
if(count>=6)
break;
}
char bol;
if(count>5)
bol='Y';
else
bol='N';
printf("%d %c\n",count,bol);
return 0;
}
int judge (char c)
{
int bl=0;
switch(c)
{
case 'Q':
if(Qcd==0)
{
bl=1;
Qcd+=2;
}
break;
case 'W':
if(Wcd==0)
{
bl=1;
Wcd+=4;
}
break;
case 'E':
if(Ecd==0)
{
bl=1;
Ecd+=3;
}
break;
case 'A':
if(Acd==0)
{
bl=1;
Acd+=1;
}
break;
}
if(bl==1)
if(c!=lst)
{
count++;
lst=c;
}
return 0;
}

2024.06.25 象棋中的马/没做完

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */  

#include<stdio.h>
int n,m,x,y,a[401][401];
void dfs(int x,int y,int step);
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<401;i++)
for(int j=0;j<401;j++)
a[i][j]=-1;//这里初始化-1 表示为无法到达
dfs(1,1,0);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
printf("%5d",a[i][j]);
printf("\n");
}
return 0;
/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
}
void dfs(int x,int y,int step)
{
if(step>n*m)
return 0;
if(x>m||y>n||x<=0||y<=0)
return 0;
if(a[x][y]>step||a[x][y]==-1)
a[x][y]=step;



int dub=step;
dfs(x+2,y+1,++step);
step=dub;
dfs(x+2,y-1,++step);
step=dub;
dfs(x-2,y+1,++step);
step=dub;
dfs(x-2,y-1,++step);
step=dub;
dfs(x+1,y+2,++step);
step=dub;
dfs(x-1,y+2,++step);
step=dub;
dfs(x+1,y-2,++step);
step=dub;
dfs(x-1,y-2,++step);
return 0;
}

递归题

2024.05.08 回文字符/递归

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>//TENET
#include <string.h>
char baka[100];
int cirno(char*,int);
int main(void)
{
gets(baka);
cirno(baka,0);
}
int cirno(char* busu,int n)
{

if(busu[n]==busu[strlen(busu)-n-1])
{
if(n==strlen(busu)/2)
{
printf("Yes\n");
return 0;
}
cirno(busu,n+1);
}
else
printf("No\n");
return 0;
}

2024.05.08 杀鸡用牛刀/递归

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
int sum(int n, int m)
{
if (m == n)
return m;
else
return m + sum(n, m - 1);
}
int main(void)
{
int n, m, s = 0;
scanf("%d %d", &n, &m);
printf("The sum from %d to %d is %d.\n", n, m, sum(n, m));
return 0;
}

2024.05.13 迭代求平方根

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
double x=0.0,p=0.0;
float e=0.0;
double cirno (double);
int main (void)
{
scanf("%lf %g",&x,&e);
p=e;
printf("%.8lf\n",cirno(p));
}
double cirno(double q)
{
if((q*q-x)*(q*q-x)<(e*e))
return q;
else
return cirno(0.5*(q+(x/q)));
}

2024.05.13 最大公约数/递归

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
int cirno(int,int);
int main(void)
{
int m=0,n=0;
scanf("%d %d",&n,&m);
printf("%d\n",cirno(n,m));
}
int cirno(int n1,int m1)
{
if(m1<=n1&&n1%m1==0)
return m1;
else if(n1<m1)
return cirno(m1,n1);
else
return cirno(m1,n1%m1);
}

2024.05.13 数列之和/递归

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <math.h>
float cirno(int);
float tot=0.0;
int p=1;
int main (void)
{
int n=0;
scanf("%d",&n);
if(n==1)
printf("1\n");
else
printf("%f\n",cirno(n));
}
float cirno (int m)
{
if(p==1)
tot=1;
else
tot+=((1/(float)p)*(pow(-1,p)));
if(p==m)
return(tot);
else
{
p++;
return(cirno(m));
}
}

2024.06.13 递归函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */  

#include <stdio.h>
void PrintChar(int number,char c){
int i;
for ( i=0 ; i< number; i++)
printf("%c",c);
}

// ????-----------????
char RecursionFunction(int n, char c);

int main(){
char c; int n;
scanf("%d %c",&n,&c);
RecursionFunction(n,c);
return 0;
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
char RecursionFunction(int n, char c)
{
if(n<=0)
{
printf("\n");
printf("RecursionFunction has been over !\n");
return 0;
}
PrintChar(n,c);
switch(c)
{
case '#':n-=1;c='*';break;
case '*':n+=2;c='?';break;
case '?':n+=3;c='+';break;
case '+':n-=6;c='#';break;
}
RecursionFunction(n,c);
}

链表题

2024.06.03 链表大折腾/奇偶/注释损坏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include "stdio.h"
#include "stdlib.h"

struct node
{ int data;
struct node * next;
} ;

typedef struct node NODE;
typedef struct node * PNODE;
void outlist( PNODE );
void createList(PNODE);
void deployList(PNODE);

int main ( )
{ int num=1;
PNODE head;

head = (PNODE)malloc( sizeof(NODE) );
head->next = NULL;
head->data = -1;

createList(head);// 杩欐槸浣犺瀹屾垚鐨勫嚱鏁?
deployList(head);// 杩欐槸浣犺瀹屾垚鐨勫嚱鏁?
outlist( head );
return 0;
}

void outlist( PNODE head )
{ PNODE p;
p = head->next;
while ( p != NULL )
{ printf("%d\n", p->data);
p = p->next;
}
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */

void createList(PNODE h)
{
PNODE m=h;
while(1)
{
PNODE p=NULL;
p=(PNODE)malloc( sizeof(NODE) );
while(h->next!=NULL)
h=h->next;
scanf("%d",&p->data);
if(p->data==0)
{
free(p);
p=NULL;
break;
}
p->next=h->next;
h->next=p;
}
h=m;
}
void deployList(PNODE h)
{
PNODE q;
int num=0;
q = h->next;
while ( q != NULL )
{
if(q->data%2!=0)
num++;
q = q->next;
}
for(int n=0;n<num;n++)
{
PNODE fst=h;
while(h->next!=NULL)
{
h=h->next;

}
PNODE end=h;
h=fst;
while(h->next->data%2==0)
{
h=h->next;

}
PNODE p=NULL;
p=(PNODE)malloc( sizeof(NODE) );
end->next=p;
p->next=NULL;
p->data=h->next->data;
h->next=h->next->next;
h=fst;
}
}

2024.06.03 链表排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include "stdio.h"
#include "stdlib.h"

struct node
{ int data;
struct node * next;
} ;

typedef struct node NODE;
typedef struct node * PNODE;
void outlist( PNODE );
void sortlist( PNODE, int);

int main ( )
{ int num=1;
PNODE head;

head = (PNODE)malloc( sizeof(NODE) );
head->next = NULL;
head->data = -1;

while ( num!=0 )
{ scanf("%d", &num);
if ( num!=0 )
sortlist( head, num);
}
outlist( head );
return 0;
}

void outlist( PNODE head )
{ PNODE p;
p = head->next;
while ( p != NULL )
{ printf("%d\n", p->data);
p = p->next;
}
}

/* This is an example for list. Please programme your code like it.
sortlist( PNODE h, int num )
{ PNODE p;
p = (PNODE)malloc( sizeof(NODE) );
p->data = num;
p->next = h->next;
h->next = p;
}
*/

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
void sortlist( PNODE h, int num )
{ PNODE p;
p = (PNODE)malloc( sizeof(NODE) );
int bl=0;
while(h->next!=NULL)
{
if(h->next->data>num)
break;
if(h->data==num)
bl=1;
h=h->next;
}
if(h->data==num)
bl=1;
if(bl==0)
{
p->data = num;
p->next =h->next;
h->next = p;
}
}

2024.06.03 交替插入链表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include "stdio.h"
#include "stdlib.h"

struct node
{ int data;
struct node * next;
} ;

typedef struct node NODE;
typedef struct node * PNODE;
void outlist( PNODE );
void createList(PNODE);
void deployList(PNODE head1,PNODE head2,PNODE head3);

int main ( )
{ int num=1;
PNODE head1,head2,head3;

head1 = (PNODE)malloc( sizeof(NODE) );
head1->next = NULL;
head1->data = -1;

head2 = (PNODE)malloc( sizeof(NODE) );
head2->next = NULL;
head2->data = -1;

head3 = (PNODE)malloc( sizeof(NODE) );
head3->next = NULL;
head3->data = -1;

createList(head1);// 杩欐槸浣犺瀹屾垚鐨勫嚱鏁?
createList(head2);// 杩欐槸浣犺瀹屾垚鐨勫嚱鏁?
deployList(head1,head2,head3);// 杩欐槸浣犺瀹屾垚鐨勫嚱鏁?
outlist( head1 );
return 0;
}

void outlist( PNODE head )
{ PNODE p;
p = head->next;
while ( p != NULL )
{ printf("%d\n", p->data);
p = p->next;
}
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */

void createList(PNODE head)
{
int num;
PNODE p = NULL;

scanf("%d", &num);
while (num != 0)
{
while(head->next!=NULL)
head=head->next;
p = (PNODE)malloc(sizeof(NODE));
p->data = num;
p->next = head->next;
head->next = p;

scanf("%d", &num);
}
}

void deployList(PNODE head1, PNODE head2, PNODE head3)
{
PNODE p1 = head1->next;
PNODE p2 = head2->next;
PNODE p3 = head3;

while (p1 != NULL && p2 != NULL)
{
p3->next = p1;
p1 = p1->next;
p3 = p3->next;

p3->next = p2;
p2 = p2->next;
p3 = p3->next;
}
if (p1 != NULL)
p3->next = p1;

if (p2 != NULL)
p3->next = p2;
}

2024.06.03 正序链表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include "stdio.h"
#include "stdlib.h"

struct node
{ int data;
struct node * next;
} ;

typedef struct node NODE;
typedef struct node * PNODE;

void outlist( PNODE );
void ins_list( PNODE h, int num ) ;
int main ( void)
{ int num=1;
PNODE head;

head = (PNODE)malloc( sizeof(NODE) );
head->next = NULL;
head->data = -1;

while(num!=0){
scanf("%d", &num);
if(num!=0)
ins_list(head,num);
}

outlist( head );
return 0;
}

void outlist( PNODE head )
{ PNODE p;
p = head->next;
while ( p != NULL )
{ printf("%d\n", p->data);
p = p->next;
}
}

/* This is an example for list. Please programme your code like it.*/

void ins_list(PNODE h,int num)
{
PNODE p;
p = (PNODE)malloc(sizeof(NODE));
while(h->next!=NULL){
h=h->next;
}
p->data=num;
p->next=NULL;
h->next=p;
}

2024.06.04 链表循环节

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <stdlib.h>

int st=0,ed=0;
typedef struct node
{ int data;
struct node * next;
} NODE;

NODE * find( NODE * , int * );
void outputring( NODE * );
void change( int , int , NODE * );

void outputring( NODE * pring )
{
NODE * p;
p = pring;
//printf("ass%d", p->data);
if ( p == NULL )
printf("NULL");
else
do
{
printf("%d", p->data);
p = p->next;
if(p==NULL){
break;
}
}while(p!= pring);
printf("\n");
return;

}

int main()
{ int n, m;
NODE * head, * pring;

scanf("%d%d", &n, &m);
head = (NODE *)malloc( sizeof(NODE) );
head->next = NULL;
head->data = -1;

change( n, m, head );
pring = find( head, &n );
printf("ring=%d\n", n);
outputring( pring );

return 0;
}

/* Here is waiting for you.
void change( int n, int m, NODE * head )
{
}

NODE * find( NODE * head, int * n )
{
}
*/

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
void change( int n, int m, NODE * head )
{
int sh[1000]={0};
int mo[1000]={0};
int bl=0;
for(int i=0;;i++)
{
sh[i]=n*10/m;
mo[i]=n*10%m;
for(int j=0;j<i;j++)
if(sh[i]==sh[j]&&mo[i]==mo[j])
{
st=j;
ed=i;
bl=1;
break;
}
n=mo[i];


if(n==0)
{
st=i+1;
break;
}
if(bl!=0)
break;
}

for(int k=0;k<st;k++)
{
while(head->next!=NULL)
head=head->next;
NODE* p=(NODE*)malloc(sizeof(NODE));
p->data=sh[k];
p->next=NULL;
head->next=p;
}
if(bl!=0)
{
for(int k=st;k<ed;k++)
{
while(head->next!=NULL)
head=head->next;
NODE* p=(NODE*)malloc(sizeof(NODE));
p->data=sh[k];
p->next=NULL;
head->next=p;
}
}
}

NODE * find( NODE * head, int * n )
{
if(ed>st)
{
*n=ed-st;
NODE* a=head->next;
for(int k=0;k<st;k++)
a=a->next;
//printf("ass%d",a->data);
return a;
}
else
{
*n=0;
return NULL;
}
}

2024.06.11 链表小数节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <stdlib.h>

int st=0,ed=0;
typedef struct node
{ int data;
struct node * next;
} NODE;

NODE * find( NODE * , int * );
void outputring( NODE * );
void change( int , int , NODE * );

void outputring( NODE * pring )
{
NODE * p;
p = pring;
//printf("ass%d", p->data);
if ( p == NULL )
printf("NULL");
else
do
{
printf("%d", p->data);
p = p->next;
if(p==NULL){
break;
}
}while(p!= pring);
printf("\n");
return;

}

int main()
{ int n, m;
NODE * head, * pring;

scanf("%d%d", &n, &m);
head = (NODE *)malloc( sizeof(NODE) );
head->next = NULL;
head->data = -1;

change( n, m, head );
pring = find( head, &n );
printf("ring=%d\n", n);
outputring( pring );

return 0;
}

/* Here is waiting for you.
void change( int n, int m, NODE * head )
{
}

NODE * find( NODE * head, int * n )
{
}
*/

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
void change( int n, int m, NODE * head )
{
int sh[1000]={0};
int mo[1000]={0};
int bl=0;
for(int i=0;;i++)
{
sh[i]=n*10/m;
mo[i]=n*10%m;
for(int j=0;j<i;j++)
if(sh[i]==sh[j]&&mo[i]==mo[j])
{
st=j;
ed=i;
bl=1;
break;
}
n=mo[i];


if(n==0)
{
st=i+1;
break;
}
if(bl!=0)
break;
}

for(int k=0;k<st;k++)
{
while(head->next!=NULL)
head=head->next;
NODE* p=(NODE*)malloc(sizeof(NODE));
p->data=sh[k];
p->next=NULL;
head->next=p;
}
if(bl!=0)
{
for(int k=st;k<ed;k++)
{
while(head->next!=NULL)
head=head->next;
NODE* p=(NODE*)malloc(sizeof(NODE));
p->data=sh[k];
p->next=NULL;
head->next=p;
}
}
}

NODE * find( NODE * head, int * n )
{
if(ed>st)
{
*n=ed-st;
NODE* a=head->next;
for(int k=0;k<st;k++)
a=a->next;
//printf("ass%d",a->data);
return a;
}
else
{
*n=0;
return NULL;
}
}

2024.06.12 链表查找

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */  

#include <stdio.h>
#include <stdlib.h>

int st=0,ed=0;
typedef struct node
{ int data;
struct node * next;
} NODE;

NODE * find( NODE * , int * );
void outputring( NODE * );
void change( int , int , NODE * );

void outputring( NODE * pring )
{
NODE * p;
p = pring;
//printf("ass%d", p->data);
if ( p == NULL )
printf("NULL");
else
do
{
printf("%d", p->data);
p = p->next;
if(p==NULL){
break;
}
}while(p!= pring);
printf("\n");
return;

}

int main()
{ int n, m;
NODE * head, * pring;

scanf("%d%d", &n, &m);
head = (NODE *)malloc( sizeof(NODE) );
head->next = NULL;
head->data = -1;

change( n, m, head );
pring = find( head, &n );
printf("ring=%d\n", n);
outputring( pring );

return 0;
}

/* Here is waiting for you.
void change( int n, int m, NODE * head )
{
}

NODE * find( NODE * head, int * n )
{
}
*/

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
void change( int n, int m, NODE * head )
{
int sh[1000]={0};
int mo[1000]={0};
int bl=0;
for(int i=0;;i++)
{
sh[i]=n*10/m;
mo[i]=n*10%m;
for(int j=0;j<i;j++)
if(sh[i]==sh[j]&&mo[i]==mo[j])
{
st=j;
ed=i;
bl=1;
break;
}
n=mo[i];


if(n==0)
{
st=i+1;
break;
}
if(bl!=0)
break;
}

for(int k=0;k<st;k++)
{
while(head->next!=NULL)
head=head->next;
NODE* p=(NODE*)malloc(sizeof(NODE));
p->data=sh[k];
p->next=NULL;
head->next=p;
}
if(bl!=0)
{
for(int k=st;k<ed;k++)
{
while(head->next!=NULL)
head=head->next;
NODE* p=(NODE*)malloc(sizeof(NODE));
p->data=sh[k];
p->next=NULL;
head->next=p;
}
}
}

NODE * find( NODE * head, int * n )
{
if(ed>st)
{
*n=ed-st;
NODE* a=head->next;
for(int k=0;k<st;k++)
a=a->next;
//printf("ass%d",a->data);
return a;
}
else
{
*n=0;
return NULL;
}
}

其他

字符串题

2024.05.26 字符串排序/C Primer Plus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <string.h>
#define SIZE 81
#define LIM 20
#define HALT ""
void stsrt(char *strings[],int num);
char * s_gets(char *st,int n);

int main(void)
{
char input[LIM][SIZE];
char *ptstr[LIM];
int ct =0;
int k;

printf("Input up to %d lines,and I will sort them.\n",LIM);
printf("To stop,press the Enter key at a line's start.\n");
while(ct < LIM && s_gets(input[ct],SIZE)!=NULL && input[ct][0]!='\0')
{
ptstr[ct]=input[ct];
ct++;
}
stsrt(ptstr,ct);
puts("\nHere's the sorted list:\n");
for(k=0;k<ct;k++)
puts(ptstr[k]);
return 0;
}
void stsrt(char *strings[],int num)
{
char *temp;
int top,seek;

for(top=0;top<num-1;top++)
for(seek=top+1;seek<num;seek++)
if(strcmp(strings[top],strings[seek])>0)
{
temp=strings[top];
strings[top]=strings[seek];
strings[seek]=temp;
}
}

char * s_gets(char * st,int n)
{
char * ret_val;
int i=0;

ret_val=fgets(st,n,stdin);
if(ret_val)
{
while(st[i]!='\n'&&st[i]!='\0')
i++;
if(st[i]=='\n')
st[i]='\0';
else
while(getchar()!='\n')
continue;
}
return ret_val;
}

The Akina histroy goes on~