文章目录
- 矩阵转置
- 上三角矩阵判定
- 有序序列判断
- 小乐乐与欧几里得
- 空心正方形图案
- 箭形图案
- 公务员面试
- 矩阵转置
define _CRT_SECURE_NO_WARNINGS
include<stdio.h>
int main()
{
int n = 0;
int m = 0;
int i = 0;
int j = 0;
int arr[10][10] = { 0 };
scanf("%d %d", &n,&m);
for (int i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%d", &arr[i][j]);
}
}
//输出
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("%d ", arr[j][i]);
}
printf("\n");
}
return 0;
}
- 上三角矩阵判定
define _CRT_SECURE_NO_WARNINGS
include<stdio.h>
int main()
{
int n = 0;
int i = 0;
int j = 0;
int arr[10][10] = { 0 };
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &arr[i][j]);
}
}
int flag = 1;//是上三角形矩阵
for (int i = 0; i < n; i++)
{
for (j = 0; j < i; j++)
{
if (arr[i][j] != 0)
{
flag = 0;
goto end;
}
}
}
end:
if (flag == 0)
{
printf("NO\n");
}
else
printf("YES\n");
}
- 有序序列判断
define _CRT_SECURE_NO_WARNINGS
include<stdio.h>
int main()
{
int n = 0;
scanf("%d", &n);
int i = 0;
int flag1 = 0;
int flag2 = 0;
int arr[100] = { 0 };
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
if (i > 0)
{
if (arr[i] > arr[i - 1])
{
flag1 = 1;
}
else if(arr[i]<arr[i-1])
{
flag2 = 1;
}
else
{
;
}
}
}
if (flag1 + flag2 <= 1)
{
printf("sorted\n");
}
else
{
printf("unsorted\n");
}
return 0;
}
- 小乐乐与欧几里得
define _CRT_SECURE_NO_WARNINGS
include<stdio.h>
long long f(long long a, long long b)
{
long long c = 0;
long long d = 1;
while (d)
{
c = a / b;
d = a % b;
a = b;
b = d;
}
return a;
}
int main()
{
long long a = 0;
long long b = 0;
long long ret = 0;
long long e = 0;
scanf("%lld%lld", &a, &b);
if (a > b)
{
ret=f(a, b);
}
else
{
ret=f(b, a);
}
e = (a * b) / ret;
printf("%lld\n", e + ret);
return 0;
}
- 空心正方形图案
define _CRT_SECURE_NO_WARNINGS
include<stdio.h>
int main()
{
int n = 0;
while (scanf("%d",&n) != EOF)
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if ((i == 0) || (j == 0) || (i == n - 1) || (j == n - 1))
{
printf("* ");
}
else
printf(" ");
}
printf("\n");
}
}
return 0;
}
- 箭形图案
include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
//循环读入n
while(scanf("%d", &n) != EOF) {
//设置space,star值的初始值
int space = 2*n;
int star = 1;
//外循环开始遍历每一行
for(int i = 0; i < n+1; ++i) {
//挨个输出空格的个数
for(int j = 0; j < space; ++j)
printf(" ");
//挨个输出星号的个数
for(int j = 0; j < star; ++j)
printf("*");
//输出剩下的空格
for(int j = 0; j < 2*n+1-space-star; ++j)
printf(" ");
//更新下一行的空格数和星号个数
space -= 2;
star += 1;
printf("\n");
}
//下半部分的初值设置
space = 2;
star = n;
//外循环开始遍历每一行,内循环流程和上述一样
for(int i = 0; i < n; ++i) {
for(int j = 0; j < space; ++j)
printf(" ");
for(int j = 0; j < star; ++j)
printf("*");
for(int j = 0; j < 2*n+1-space-star; ++j)
printf(" ");
//更新下一行的空格和星号个数
space += 2;
star -= 1;
printf("\n");
}
}
return 0;
}
- 公务员面试
define _CRT_SECURE_NO_WARNINGS
include<stdio.h>
int main()
{
int n = 0;
int score = 0;
int max = 0;
int min = 100;
int sum = 0;
while (scanf("%d", &score)==1)
{
n++;
if (score > max)
max = score;
if (score < min)
min = score;
sum += score;
if (n == 7)
{
printf("%.2lf\n",(sum - max - min) / 5.0);
max = 0;
min = 100;
sum = 0;
n = 0;
}
}
return 0;
}