-1005 Sell It Right(20)
#include<stdio.h>
int main()
{
char s[100];
scanf("%s",s);
int i=0,sum=0;
int output[10];
int flag=1;
while(s[i]!='\0')
sum+=(int)s[i++]-48;
int stack=0;
while(sum>=1)
{
output[stack++]=sum%10;
sum/=10;
}
while(--stack>=0)
{
if(flag==1)
flag=0;
else
printf(" ");
switch(output[stack])
{
case 0:
printf("zero");break;
case 1:
printf("one");break;
case 2:
printf("two");break;
case 3:
printf("three");break;
case 4:
printf("four");break;
case 5:
printf("five");break;
case 6:
printf("six");break;
case 7:
printf("seven");break;
case 8:
printf("eight");break;
case 9:
printf("nine");break;
}
}
}
点3过不了 但是牛客网能过???
-1006 Sign In and Sign Out(25)
#include<stdio.h>
#include<stdlib.h>
typedef struct people *People;
struct people
{
char id[15];
int in;
int out;
};
int comp1(const void *a, const void *b)
{
return (*(People)a).in - (*(People)b).in;
}
int comp2(const void *a, const void *b)
{
return (*(People)b).out - (*(People)a).out;
}
int main()
{
People p;
int n;
scanf("%d",&n);
p=(People)malloc(sizeof(People)*n);
int inh,inm,ins,outh,outm,outs;
for(int i=0;i<n;i++)
{
scanf("%s %d:%d:%d %d:%d:%d",p[i].id,&inh,&inm,&ins,&outh,&outm,&outs);
p[i].in=inh*3600+inm*60+ins;
p[i].out=outh*3600+outm*60+outs;
}
qsort(p, n, sizeof(p[0]), comp1);
printf("%s ",p[0].id);
qsort(p, n, sizeof(p[0]), comp2);
printf("%s",p[0].id);
}
-1008 Elevator(20)
include<stdio.h>
int main()
{
int N,sum=0,last=0,now,temp=0;
scanf("%d",&N);
int floor[N];
int i;
for(i=0;i<N;i++)
{
scanf("%d",&now);
if(now>last)
sum+=6*(now-last);
else
sum+=4*(last-now);
last=now;
}
sum+=5*N;
printf("%d",sum);
}
-1083 List Grades(25)
#include<stdio.h>
#include<stdlib.h>
typedef struct people *People;
struct people
{
char id[15];
char name[10];
int score;
};
int comp1(const void *a, const void *b)
{
return (*(People)b).score - (*(People)a).score;
}
int main()
{
People p;
int n,max,min,num=0;
scanf("%d",&n);
p=(People)malloc(sizeof(People)*n);
for(int i=0;i<n;i++)
scanf("%s %s %d",p[i].name,p[i].id,&p[i].score);
scanf("%d %d",&min,&max);
if(max<=min)
{
max=max+min;
min=max-min;
max=max-min;
}
//确保上下界
for(int i=0;i<n;i++)
{
if(p[i].score<min||p[i].score>max)
{
p[i].score=-1;
num+=1;
}
}
qsort(p, n, sizeof(p[0]), comp1);
if(num==n)
{
printf("NONE\n");
return 0;
}
for(int i=0;i<n-num;i++)
printf("%s %s\n",p[i].name,p[i].id);
}
点3异常退出,暂时不知道为啥