George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.
Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).
The first line contains current time s as a string in the format "hh:mm". The second line contains time t in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59.
In the single line print time p — the time George went to bed in the format similar to the format of the time in the input.
05:50 05:44
00:06
00:00 01:00
23:00
00:01 00:00
00:01
题意:第一个睡醒的时间,第二个开始睡的时间,问睡了多久,可能过了一天
题解:直接化成多少分钟,+1440然后模1440,再换成小时分钟就可以了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
int x1,x2,y1,y2,res;
char ch;
while(scanf("%d%c%d",&x1,&ch,&y1)>0)
{
scanf("%d%c%d",&x2,&ch,&y2);
res=(x1*60+y1-x2*60-y2+1440)%1440;
printf("%02d:%02d\n",res/60,res%60);
}
return 0;
}
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a goodround. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Print a single integer — the answer to the problem.
3 5 1 2 3 1 2 2 3 3
0
3 5 1 2 3 1 1 1 1 1
2
3 1 2 3 4 1
3
题意:给n个要求的数,给m个有的数,大于要求的数可以当要求的数用
题解:2个数组都升序排序,2个数组都从最后贪心取上去,可以取就取并标记,就可以得到结果了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int a[3008],b[3008],mark[3008];
int cmp(const void *a,const void *b)
{
return *(int *)a<*(int *)b?-1:1;
}
int main()
{
int i,j,n,m,ans;
while(scanf("%d%d",&n,&m)>0)
{
memset(mark,0,sizeof(mark));
for(i=0;i<n;i++) scanf("%d",a+i);
for(i=0;i<m;i++) scanf("%d",b+i);
qsort(a,n,sizeof(a[0]),cmp);
qsort(b,m,sizeof(a[0]),cmp);
for(j=m-1,i=n-1;i>=0;i--)
{
if(j>=0&&b[j]>=a[i]){ j--; mark[i]=1; }
}
for(ans=i=0;i<n;i++) if(!mark[i]) ans++;
printf("%d\n",ans);
}
return 0;
}
George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George's current array as b1, b2, ..., b|b| (record |b| denotes the current length of the array). Then one change is a sequence of actions:
- Choose two distinct indexes i and j (1 ≤ i, j ≤ |b|; i ≠ j), such that bi ≥ bj.
- Get number v = concat(bi, bj), where concat(x, y) is a number obtained by adding number y to the end of the decimal record of number x. For example, concat(500, 10) = 50010, concat(2, 2) = 22.
- Add number v to the end of the array. The length of the array will increase by one.
- Remove from the array numbers with indexes i and j. The length of the array will decrease by two, and elements of the array will become re-numbered from 1 to current length of the array.
George played for a long time with his array b and received from array b an array consisting of exactly one number p. Now George wants to know: what is the maximum number of elements array b could contain originally? Help him find this number. Note that originally the array could contain only positive integers.
The first line of the input contains a single integer p (1 ≤ p < 10100000). It is guaranteed that number p doesn't contain any leading zeroes.
Print an integer — the maximum number of elements array b could contain originally.
9555
4
10000000005
2
800101
3
45
1
1000000000000001223300003342220044555
17
19992000
1
310200
2
题意:一个数组,每次将2个数合并,并且大的排在前面,给出合并完的数,问最多是又多少个数组成的
题解:从一开始贪心,若当前数比下一个数大,则答案加一,否则初始化答案为一,最后就是结果(一个位当一个数,若后面有零,则要带上全部后缀零)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
char s[1000008],now[1000008],temp[1000008];
int i,j,len,ans,ls;
int main()
{
while(scanf("%s",s)>0)
{
ls=strlen(s);
now[0]=s[0];
for(i=1;s[i]=='0';i++) now[i]=s[i];
now[len=i]='\0';
for(ans=1;i<ls;)
{
temp[j=0]=s[i++];
for(j++;i<ls&&s[i]=='0';j++,i++) temp[j]=s[i];
temp[j]='\0';
if(len>j) ans++;
else if(len==j&&strcmp(now,temp)>=0) ans++;
else ans=1;
len=len+j;
strcat(now,temp);
}
printf("%d\n",ans);
}
return 0;
}