2010西安电子科技大学计算机机试题目
程序员文章站
2024-03-11 20:00:19
...
由于题目是相机拍摄的,难免不清楚。
Problem A
#include <stdio.h>
int val[1001];
void Bubble_Sort(int a[],int n)
{
int i,j,tmp;
for(i = 0;i < n;i++)
{
for(j = i + 1;j < n;j++)
if(a[i] > a[j]) tmp = a[i],a[i] = a[j],a[j] = tmp;
}
}
int main()
{
int tmp;
int cnt = 0;
int i,j;
while(scanf("%d",&val[cnt]) && val[cnt] != 0) cnt++;
for(i = 0;i < cnt;i++)
{
tmp = val[i];
val[i] = 0;
while(tmp != 0)
{
val[i] += tmp % 10;
tmp /= 10;
}
Bubble_Sort(val,i + 1);
}
printf("%d",val[0]);
for(j = 1;j < i;j++) printf(" %d",val[j]);
return 0;
}
Problem B
#include <stdio.h>
#define MAX 100
#define bool _Bool
#define false 0
#define true 1
int val[MAX][MAX];
int n,m;
//判断是否是所在列的最大值
bool is_Max(int value,int col)
{
int i;
for(i = 0;i < m;i++)
{
if(value < val[i][col]) return false;
}
return true;
}
int main()
{
int i,j;
int min;
int index;
bool flag = false;
freopen("/home/yan/input","r",stdin);
scanf("%d %d",&m,&n);
for(i = 0;i < m;i++)
{
for(j = 0;j < n;j++) scanf("%d",&val[i][j]);
}
for(i = 0;i < m;i++)//找出每行最小的元素
{
min = 999999;
index = -1;
for(j = 0;j < n;j++)
{
if(min > val[i][j])
{
min = val[i][j];
index = j;
}
//最小值即为val[i][index]
}
//printf("%d\n",val[i][index]);
if(is_Max(val[i][index],index) == true)
printf("%d %d %d\n",i,index,val[i][index]),flag = true;
}
if(flag == false) printf("no\n");
return 0;
}
Problem C
#include <stdio.h>
char cache[51];
int num;//存储重复的次数
int main()
{
freopen("/home/yan/input","r",stdin);
int i,j;
char tmp;
int flag = 0;
num = 0;
int rept;
scanf("%s",cache);
for(i = 0;cache[i] != '\0';i++)
{
//printf("%c",cache[i]);
if(cache[i] >= 'a' && cache[i] <='z')
{
tmp = cache[i];
printf("%c",tmp);
}
else
{
while(cache[i] >= '0' && cache[i] <='9')
{
num = num * 10 + cache[i] - '0';
i++;
flag = 1;
}
if(flag == 1)
{
i--;
flag =0;
}
for(j = 1;j < num;j++)
printf("%c",tmp);
num = 0;
}
}
return 0;
}
Problem D
#include <stdio.h>
int n;
int val[31];
int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
}
int main()
{
int i;
scanf("%d",&n);
int ans = 0;
for(i = 0;i < n;i++)
{
scanf("%d",&val[i]);
}
for(i = 1;i < n;i++)
{
qsort(&val[i - 1],n - i + 1,sizeof(val[0]),cmp);
ans += val[i - 1] + val[i];
val[i] += val[i - 1];
}
printf("%d",ans);
return 0;
}
上一篇: 【C++】makefile
推荐阅读