Connection Status:
Competition Arena > Stream
SRM 105 · 2002-07-18 · by Azot
Class Name: Stream
Return Type: int[]
Method Name: breakup
Arg Types: (vector<int>, int)
Problem Statement

Problem Statement

Write a method which breaks up a stream of bits into chunks of some given length, converts each chunk into an integer, and returns an array of integers that represents these chunks. The stream is represented by an array of integers. Each integer's binary equivalent represents a 32 bit portion of the stream.

If the stream cannot be divided into chunks of equal length, then pad the end of the stream with zeros until chunks of equal length can be obtained.

Constraints

  • stream contains between 1 and 4 elements, inclusive.
  • Each element of stream is between 0 and 2147483647, inclusive.
  • size is between 1 and 32, inclusive.
Examples
0)
{512, 1024, 2048, 4096}
16
Returns: { 0,  512,  0,  1024,  0,  2048,  0,  4096 }
1)
{2096545431}
5
Returns: { 15,  19,  27,  11,  29,  5,  24 }
2)
{511, 255, 63, 31}
8
Returns: { 0,  0,  1,  255,  0,  0,  0,  255,  0,  0,  0,  63,  0,  0,  0,  31 }
3)
{456, 235, 356, 234}
19
Returns: { 0,  29184,  1,  438272,  178,  0,  7488 }
4)
{111111111, 222222222, 100000, 64}
29
Returns: { 13888888,  473234270,  117440707,  167772160,  8388608 }
32)
{32,255}
4
Returns: { 0,  0,  0,  0,  0,  0,  2,  0,  0,  0,  0,  0,  0,  0,  15,  15 }

32 is 255 is 00000000000000000000000000100000 00000000000000000000000011111111 Breaking it down to chunks of 4 bits in length yields: 0000 0000 0000 0000 0000 0000 0010 0000 0000 0000 0000 0000 0000 0000 1111 1111 0 0 0 0 0 0 2 0 0 0 0 0 0 0 15 15

33)
{8191}
13
Returns: { 0,  127,  8064 }

8191 padding 00000000000000000001111111111111 0000000 0000000000000 0000001111111 1111110000000 0 127 8064 Notice that without the padding the stream could not have been divided into chunks of 13 bits.

Submissions are judged against all 37 archived test cases, of which 7 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Stream with a public method vector<int> breakup(vector<int> stream, int size) · 37 test cases · 2 s / 256 MB per case

Submitting as anonymous