大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
思路:虽然代码长度比较长,但是性能确实不错,速度也挺快,没有用到排序算法,一遍输入结束,就能得到结果。
代码如下(编译器是dev,语言是C语言):
#include#includechar maxxm[11],minxm[11],maxxh[11],minxh[11],temp,xm[11],xh[11];
int n,i,j,k,s,summax = 0,summin = 0,sum;
int main(){scanf("%d",&n);
getchar();
for(i = 1;i<=n;i++){j = 0,sum = 0;
while(true){scanf("%c",&temp);
if(temp == '\n'){break;
}
if(temp == ' '){if(j == 0){xm[k] = NULL;
}else if(j == 1){xh[k] = NULL;
}
j++;
k = 0;
continue;
}
if(j == 0){xm[k++] = temp;
}else if(j == 1){xh[k++] = temp;
}else if(j == 2){sum = sum*10 +temp -48;
}
}
if(i == 1){summax = sum;
summin = sum;
for(s = 0;;s++){if(xm[s] == NULL){break;
}
maxxm[s] = xm[s];
}
maxxm[s] = NULL;
for(s = 0;;s++){if(xh[s] == NULL){break;
}
maxxh[s] = xh[s];
}
maxxh[s] = NULL;
for(s = 0;;s++){if(xm[s] == NULL){break;
}
minxm[s] = xm[s];
}
minxm[s] = NULL;
for(s = 0;;s++){if(xh[s] == NULL){break;
}
minxh[s] = xh[s];
}
minxh[s] = NULL;
}else{if(sum>summax){summax = sum;
for(s = 0;;s++){if(xm[s] == NULL){break;
}
maxxm[s] = xm[s];
}
maxxm[s] = NULL;
for(s = 0;;s++){if(xh[s] == NULL){break;
}
maxxh[s] = xh[s];
}
maxxh[s] = NULL;
}
if(sumsummin = sum;
for(s = 0;;s++){if(xm[s] == NULL){break;
}
minxm[s] = xm[s];
}
minxm[s] = NULL;
for(s = 0;;s++){if(xh[s] == NULL){break;
}
minxh[s] = xh[s];
}
minxh[s] = NULL;
}
}
}
for(i = 0;;i++){if(maxxm[i] == NULL){break;
}
printf("%c",maxxm[i]);
}
printf(" ");
for(i = 0;;i++){if(maxxh[i] == NULL){break;
}
printf("%c",maxxh[i]);
}
printf("\n");
for(i = 0;;i++){if(minxm[i] == NULL){break;
}
printf("%c",minxm[i]);
}
printf(" ");
for(i = 0;;i++){if(minxh[i] == NULL){break;
}
printf("%c",minxh[i]);
}
printf("\n");
return 0;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧