★本题目考察代码熟练度,没有用到数据结构和算法
★代码实现
#include<stdio.h> int main() { int n; int AH,AM,AS,BH,BM,BS,SH,SM,SS; scanf("%d",&n); while(n --) { SH = SM = SS = 0; scanf("%d %d %d %d %d %d",&AH,&AM,&AS,&BH,&BM,&BS); SS = AS + BS; if(SS >= 60) { SS -= 60; SM += 1; } SM = SM + AM + BM; if(SM >= 60) { SM -= 60; SH += 1; } SH = SH + AH + BH; printf("%d %d %d\n",SH,SM,SS); } return 0; }
★本题比较坑,输出格式搞了好久
★代码实现
#include <stdio.h> int main() { int m,n,i,j,flag,count,temp; int a[250],b[105]; while(scanf("%d %d",&m,&n)!=EOF && (m!=0 || n!=0)) { count = 0; for(i = 0;i < m+n;i++) scanf("%d",&a[i]); for(i = 0;i < m;i++) { flag = 0; for(j = m;j < m+n;j++) { if(a[i]==a[j]) { flag = 1; break; } } if(flag == 0) { b[count] = a[i]; count++; } } for(i = 0;i < count;i++) { for(j = 0;j < count-i-1;j++) { if(b[j] > b[j+1]) { temp = b[j]; b[j] = b[j+1]; b[j+1] = temp; } } } if(count == 0) printf("NULL\n"); else { for(i = 0;i < count;i++) printf("%d ",b[i]); printf("\n"); } } return 0; }
时间: 2024-11-06 09:28:55