Codeforces Round #130

第一次做 移动不给力啊 WLAN连了不下10次 第一题写完再那无奈的等了20分钟 WLAN艰难的以非常低的信号给连了几分钟 交完又掉了

D题不难 就是数据类型用错了

A. Dubstep
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.

Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.

For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".

Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.

Input

The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.

Output

Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.

Sample test(s)
Input
WUBWUBABCWUB
Output
ABC 
Input
WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB
Output
WE ARE THE CHAMPIONS MY FRIEND 
Note

In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.

In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".

循环查找

View Code
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include<string.h>
 4 int main()
 5 {
 6     int i,j,k,h,f = 0,v = 0,w = 0,g;
 7     char c[201],x[4],y[201];
 8     gets(c);
 9     g = 0;
10     j = 0;
11     while(j+2<strlen(c))
12     {
13         x[0] = c[j];
14         x[1] = c[j+1];
15         x[2] = c[j+2];
16         x[3] = '\0';
17         if(strcmp(x,"WUB")==0)
18         {
19             f = 1;
20             j = j+3;
21             w = j;
22             if(g)
23             {
24                 y[g] = '\0';
25                 if(v!=0)
26                 printf(" ");
27                 printf("%s",y);
28                 v++;
29                 g = 0;
30             }
31         }
32         else
33         {
34             y[g++] = c[j];
35             j++;
36         }
37     }
38     int flag = 1;
39     if(strlen(c)>3)
40     {
41         x[2] = c[strlen(c)-1];
42         x[1] = c[strlen(c)-2];
43         x[0] = c[strlen(c)-3];
44         x[3]='\0';
45         if(strcmp(x,"WUB")!=0)
46         flag =1;
47         else
48         flag = 0;
49     }
50     if(flag)
51     {
52         if(v)
53         printf(" ");
54         for(i = w ; i < strlen(c) ; i++)
55         printf("%c",c[i]);
56     }
57     printf("\n");
58     return 0;
59 }

 

View Code
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include<string.h>
 4 int main()
 5 {
 6     int i,j,k,h,f = 0,v = 0,w,g;
 7     char c[201],x[4],y[201];
 8     gets(c);
 9     g = 0;
10     j = 0;
11     while(j+2<strlen(c))
12     {
13         x[0] = c[j];
14         x[1] = c[j+1];
15         x[2] = c[j+2];
16         x[3] = '\0';
17         if(strcmp(x,"WUB")==0)
18         {
19             f = 1;
20             j = j+3;
21             w = j;
22             if(g)
23             {
24                 y[g] = '\0';
25                 if(v!=0)
26                 printf(" ");
27                 printf("%s",y);
28                 v++;
29                 g = 0;
30             }
31         }
32         else
33         {
34             y[g++] = c[j];
35             j++;
36         }
37     }
38     x[2] = c[strlen(c)-1];
39     x[1] = c[strlen(c)-2];
40     x[0] = c[strlen(c)-3];
41     x[3]='\0';
42     if(strcmp(x,"WUB")!=0)
43     {
44         if(v)
45         printf(" ");
46         for(i = w ; i < strlen(c) ; i++)
47         printf("%c",c[i]);
48         printf("\n");
49     }
50     return 0;
51 }
D. Prizes, Prizes, more Prizes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.

Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.

The sweepstake has the following prizes (the prizes are sorted by increasing of their cost):

  • a mug (costs apoints),
  • a towel (costs bpoints),
  • a bag (costs cpoints),
  • a bicycle (costs dpoints),
  • a car (costs e points).

 

Now Vasya wants to recollect what prizes he has received. You know sequence p1, p2, ..., pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Output

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Sample test(s)
Input
3


3 10 4
2 4 10 15 20
Output
1 1 1 0 0 


1
Input
4


10 4 39 2
3 5 10 11 12
Output
3 0 1 0 3 


0
Note

In the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.

这题刚开始用int WA 觉得太小了 用long 继续WA 然后用long long RE 最后用--int64 终于过了 电脑都搬窗台上去了 可怜的信号

View Code
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include<string.h>
 4 __int64 num[6];
 5 int main()
 6 {
 7     int n,i,j,a[55],x[6],d;
 8     __int64 y = 0;
 9     scanf("%d",&n);
10     for(i = 1; i <= n ; i++)
11     {
12         scanf("%d",&a[i]);
13         y+=a[i];
14     }
15     for(i = 1; i <= 5 ; i++)
16     scanf("%d",&x[i]);
17     a[0] = 0;
18     for(i = 1; i <= n ; i++)
19     {
20         a[i]+=a[i-1];
21         for(j = 5 ; j >= 1; j--)
22         {
23             if(a[i]>=x[j])
24             {
25                 d = a[i]/x[j];
26                 a[i] -= d*x[j];
27                 y = a[i];
28                 num[j] += d;
29             }
30         }
31     }
32     for(i = 1; i < 5 ; i++)
33     printf("%I64d ",num[i]);
34     printf("%I64d\n",num[5]);
35     printf("%I64d\n",y);
36     return 0;
37 }

 

posted @ 2012-07-24 01:42  _雨  阅读(338)  评论(2编辑  收藏  举报