比赛地址
A 数组替换
#include <stdio.h>
int main(){
for(int i
= 0; i
< 10; i
++ ){
int x
;
scanf("%d", &x
);
printf("X[%d] = %d\n", i
, x
<= 0 ? 1 : x
);
}
return 0;
}
B 数组填充
#include <stdio.h>
int main()
{
int x
,i
,v
;
scanf("%d", &v
);
x
=v
;
for(i
=0;i
<=9;i
++)
{
printf("N[%d] = %d\n",i
,x
);
x
=x
*2;
}
return 0;
}
C 数组选择
#include <stdio.h>
int main(){
double x
[100]={0};
for(int i
=0;i
<100;i
++)
{
scanf("%d", &x
[i
]);
if(x
[i
]<=10) printf("A[%d] = %.1f\n",i
,x
[i
]);
}
return 0;
}
D 数组中的行
#include <iostream>
using namespace std
;
int main()
{
int l
;
char op
;
cin
>> l
>> op
;
double s
=0;
for(int i
=0;i
<12;i
++)
{
for(int j
=0;j
<12;j
++)
{
double a
;
cin
>> a
;
if(i
==l
) s
+=a
;
}
}
printf("%.1lf",op
=='S' ? s
: s
/12);
}
E 数组变换
#include<stdio.h>
void stack(int x
)
{
int temp
;
scanf("%d",&temp
);
if(x
)
stack(x
-1);
printf("N[%d] = %d\n",x
,temp
);
}
int main(void)
{
stack(19);
return 0;
}
F 斐波那契数列
#include<iostream>
#include<cstdio>
using namespace std
;
int main(){
long long f
[61];
f
[0]=0,f
[1]=1;
for(int i
=2;i
<=60;i
++) f
[i
]=f
[i
-1]+f
[i
-2];
int t
;
cin
>>t
;
while(t
--){
int n
;
cin
>>n
;
printf("Fib(%d) = %lld\n",n
,f
[n
]);
}
return 0;
}
G 蛇形矩阵
#include<stdio.h>
#define N 100
int main()
{
int a
[N
][N
] = {0}, n
, m
;
int dir
[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int x
= 0, y
= -1, d
= 0, len
= 1;
scanf("%d%d", &n
, &m
);
for (int i
= 0; i
< n
*m
; i
++)
{
x
+= dir
[d
][0];
y
+= dir
[d
][1];
a
[x
][y
] = len
++;
if ( (d
==0 && (y
==m
-1 || a
[x
][y
+1])) || (d
==1 && (x
==n
-1 || a
[x
+1][y
]))
|| (d
==2 && (y
==0 || a
[x
][y
-1])) || (d
==3 && a
[x
-1][y
]) )
d
= (d
+ 1) % 4;
}
for (int i
= 0; i
< n
; i
++ )
{
for (int j
= 0; j
< m
; j
++ )
printf("%d ", a
[i
][j
]);
printf("\n");
}
return 0;
}
H 数组中的列
#include <iostream>
using namespace std
;
int main()
{
int l
;
char op
;
cin
>> l
>> op
;
double s
=0;
for(int i
=0;i
<12;i
++)
{
for(int j
=0;j
<12;j
++)
{
double a
;
cin
>> a
;
if(j
==l
) s
+=a
;
}
}
printf("%.1lf",op
=='S' ? s
: s
/12);
}
转载请注明原文地址:https://blackberry.8miu.com/read-313.html