Problem Statement
At TC University, there are a number of different majors. People in these majors occasionally switch from one major to another each year. Additionally, TCU is famous for having students who never graduate. Your task is, given a list of majors, the starting number of people in each major, and the percentages of people who switch from each major to each other major, determine the expected number of people who are in each major after a certain number of years.
The input
Thus, if the input
If a fractional number of people would switch majors, add the fractional part onto the number of people who remain in the same major they started in. Thus there are always the same number of total people at TCU. For example, if you end up with 4.7 people switching from one major 0 to major 1, and 3.3 people staying in major 0, then take the 0.7 people, and add them to the number of people who stay in the same major. Thus, in this example, 4 people would switch from major 0 to major 1, and 4 people would stay in the major 0.
Given this information, and the number of years that people are switching, determine how many people there are in each major after the given number of years have passed.
Definition
- Class:
- TCU
- Method:
- majors
- Parameters:
- String[], int[], int
- Returns:
- int[]
- Method signature:
- int[] majors(String[] percentages, int[] start, int years)
- (be sure your method is public)
Constraints
- percentages will contain between 1 and 20 elements, inclusive.
- Each element of percentages will contain between 1 and 50 characters, inclusive.
- Each element of percentages will be a space delimited list of integers (which may have leading 0's and extra, leading, or trailing spaces).
- Each element of percentages will have a number corresponding to every major.
- The sum of all the numbers in each element of percentages will be 100.
- Each number in each element of percentages will be between 0 and 100, inclusive.
- Each element of start will be between 0 and 1,000,000, inclusive.
- start will contain the same number of elements as percentages
- years will be between 0 and 10,000 inclusive.
Examples
{"99 01","99 001"}
{1000000,0}
2
Returns: { 990000, 10000 }
At the start there are 1,000,000 people in major 0, and none in major 1. During the first year, 1% of the people in major 0 switch to major 1. Thus, after one year there are 990,000 people in major 0 and 10,000 people in major 1. During the second year, 1% of the people in major 0 (0.01 * 990,000 = 9900) switch to major 1. At the same time, 99 percent of the people in major 1 switch to major 0 (0.99 * 10,000 = 9900). Since the same number of people switch from major 0 to major 1 as switch from major 1 to major 0, there is no net change in the number of people in the two majors. Thus, after two years (and after any number of years greater than two), there are 990,000 people in major 0, and 10,000 people in major 1.
{"80 1 5 14","2 76 19 3","1 3 45 51","30 32 26 12"}
{1237,625,9618,13476}
5
Returns: { 7497, 7212, 5533, 4714 }
After 1 year: {5141, 5089, 8011, 6715} After 2 years: {6309, 6309, 6574, 5764} After 3 years: {6968, 6900, 5971, 5117} After 4 years: {7308, 7129, 5677, 4842} After 5 years: {7497, 7212, 5533, 4714}
{"80 1 5 14","2 76 19 3","1 3 45 51","30 32 26 12"}
{1237,625,9618,134760}
500
Returns: { 46162, 41768, 31364, 26946 }
{" 00 100 "," 100 0 "}
{23,37}
999
Returns: { 37, 23 }
{"21 45 23 8 2 0 0 0 0 0 0 0 0 0 0 0 1","82 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1","44 11 17 19 2 5 1 0 0 0 0 0 0 0 0 0 1","75 10 1 5 7 0 0 0 1 0 0 0 0 0 0 0 1","72 20 3 4 0 0 0 0 0 0 0 0 0 0 0 0 1","21 55 23 0 0 0 0 0 0 0 0 0 0 0 0 0 1","96 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1","56 36 2 1 1 2 0 1 0 0 0 0 0 0 0 0 1","73 9 4 11 0 2 0 0 0 0 0 0 0 0 0 0 1","60 4 3 20 8 0 4 0 0 0 0 0 0 0 0 0 1","34 35 10 1 11 7 1 0 0 0 0 0 0 0 0 0 1","76 0 4 1 15 1 0 0 1 0 1 0 0 0 0 0 1","25 38 13 9 9 2 3 0 0 0 0 0 0 0 0 0 1","67 9 10 13 0 0 0 0 0 0 0 0 0 0 0 0 1","68 7 24 0 0 0 0 0 0 0 0 0 0 0 0 0 1","89 2 2 0 1 0 3 0 0 2 0 0 0 0 0 0 1","51 0 19 12 14 0 3 0 0 0 0 0 0 0 0 0 1"}
{1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}
10000
Returns: { 7969493, 4920821, 2305212, 1168083, 311060, 115495, 28153, 1, 11683, 0, 0, 0, 0, 0, 0, 0, 169999 }
{"3 10 8 2 11 4 7 10 1 6 0 0 1 1 2 0 34","3 1 6 0 0 2 3 10 0 1 4 4 6 12 6 12 30","0 5 5 3 10 10 8 3 8 6 9 7 6 3 5 7 5","7 9 5 9 4 11 5 4 7 3 1 9 0 11 7 6 2","3 7 7 11 4 7 6 11 5 2 2 11 6 12 2 3 1","0 5 10 7 1 9 6 12 1 7 6 6 4 6 1 4 15","2 8 10 11 4 9 6 10 6 4 0 2 3 7 10 6 2","5 9 0 11 9 10 7 6 7 0 2 0 6 5 7 7 9","10 12 5 10 0 5 0 5 12 5 0 7 3 4 6 7 9","9 3 10 3 11 12 0 7 0 9 3 6 8 9 9 0 1","2 7 4 10 4 11 2 2 3 4 9 12 6 1 10 3 10","7 9 0 11 11 3 3 5 3 8 0 7 1 3 3 12 14","0 0 11 0 4 5 11 1 3 6 5 6 11 6 0 3 28","7 1 6 11 1 9 0 11 8 0 4 4 1 8 4 8 17","5 7 9 3 7 6 6 8 5 3 4 4 3 11 12 5 2","11 10 6 5 9 0 11 9 2 5 4 2 4 8 1 7 6","0 12 2 9 5 3 3 12 11 9 2 5 8 4 4 8 3"}
{1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}
10000
Returns: { 722327, 1187682, 971619, 1197658, 916673, 1124359, 834319, 1333707, 895588, 773173, 527271, 880123, 780245, 1139247, 858062, 1057918, 1800029 }
{" 01 00000099 "," 99 1 "}
{1000000,0}
518
Returns: { 500001, 499999 }
{" 6 7 5 8 6 5 9 3 2 9 4 2 0 6 3 5 0 2 5 13"," 9 6 3 6 6 4 5 3 7 3 4 2 6 0 0 5 5 9 5 12"," 7 6 1 0 5 7 3 9 3 1 0 0 9 3 0 3 4 5 4 30"," 3 5 5 2 2 5 9 7 5 0 3 1 1 0 8 6 2 1 9 26"," 9 9 7 5 8 4 8 6 6 6 1 9 3 1 2 6 7 3 0 0"," 4 3 9 4 3 8 3 2 8 2 7 5 7 1 1 6 0 3 5 19"," 6 7 3 0 5 0 3 3 9 7 1 3 5 8 3 9 3 0 3 22"," 8 9 7 0 3 6 4 9 2 4 3 3 9 3 1 1 8 9 6 5"," 0 7 1 7 6 9 2 6 9 0 2 2 3 6 7 5 5 3 0 20"," 5 5 5 6 9 8 5 1 0 9 7 1 5 1 3 2 1 3 6 18"," 9 0 1 2 8 2 3 4 3 6 1 0 3 2 8 4 8 3 8 25"," 8 4 2 1 4 3 3 5 9 7 5 1 2 0 2 3 8 4 5 24"," 3 8 5 6 4 6 6 1 8 0 1 8 6 8 7 1 9 9 4 0"," 6 0 0 3 8 6 2 9 0 8 4 9 0 0 0 2 2 0 8 33"," 8 7 7 8 6 5 6 4 1 0 8 2 4 0 5 8 0 3 8 10"," 9 3 6 7 6 5 3 1 9 7 7 5 2 4 6 9 0 9 2 0"," 6 9 2 1 4 4 4 8 1 1 2 4 7 1 9 2 5 7 7 16"," 5 6 0 3 2 0 7 3 4 5 8 3 5 1 3 8 9 2 6 20"," 2 3 0 6 5 2 2 0 8 3 9 2 3 2 6 2 5 4 0 36"," 7 6 2 6 3 9 4 1 7 6 3 5 1 9 5 0 1 9 4 12"}
{305447,650982,388005,986764,328513,126095,703696,528191,242548,463778,350993,956920,784594,657414,420028,741612,337336,372824,311834,774784}
8761
Returns: { 628714, 585113, 358989, 468045, 511891, 563751, 479971, 386510, 563189, 465483, 412835, 366472, 375988, 374138, 418887, 415686, 375564, 505185, 473713, 1702234 }
{" 44 15 30 11"," 45 45 10 0"," 37 28 35 0"," 41 1 22 36 "}
{450286,924376,738273,96392}
2435
Returns: { 932933, 547030, 569015, 160349 }
{" 12 10 19 25 9 10 15"," 21 16 19 16 28 0 0"," 12 18 5 11 27 4 23"," 17 4 28 25 25 1 0"," 6 4 7 20 8 11 44"," 3 7 22 9 26 0 33"," 23 26 24 16 11 0 0"}
{780788,704628,252289,991557,672532,198617,115300}
10000
Returns: { 529539, 454731, 631840, 688434, 676549, 159535, 575083 }
{" 13 16 4 2 16 8 7 7 13 14 0"," 14 8 15 12 2 16 14 8 7 4 0"," 2 16 1 15 16 8 10 6 10 5 11"," 3 12 5 14 0 3 1 14 15 0 33"," 14 0 10 7 9 17 2 2 9 7 23"," 7 10 11 17 4 4 7 10 14 0 16"," 10 5 11 12 9 17 9 14 3 6 4"," 18 4 1 17 16 8 6 6 2 7 15"," 2 5 11 15 2 14 1 10 1 15 24"," 1 6 11 6 3 13 7 3 3 9 38"," 16 17 0 11 2 7 4 2 15 3 23"}
{342150,917055,118366,740177,699511,240697,53471,107673,262881,972051,287343}
5359
Returns: { 457293, 482160, 315160, 558028, 292395, 455693, 277237, 348689, 450593, 277971, 826156 }
{" 8 11 6 10 0 3 9 6 2 10 11 6 4 14"," 5 4 3 5 3 5 2 6 8 7 7 7 10 28"," 2 9 13 4 3 4 6 9 2 3 0 2 5 38"," 8 12 2 5 6 12 0 4 6 3 7 0 1 34"," 5 2 7 5 6 5 2 13 14 2 3 0 3 33"," 5 9 0 7 0 7 6 3 5 12 9 8 8 21"," 1 7 2 6 5 13 6 5 10 3 12 5 5 20"," 6 7 9 10 3 9 10 0 5 11 2 3 5 20"," 7 8 5 12 13 7 10 5 6 14 9 4 0 0"," 7 13 8 11 4 9 3 11 5 10 6 1 7 5"," 12 8 9 13 1 8 10 11 5 0 7 8 8 0"," 1 6 3 5 9 12 3 4 7 13 1 13 10 13"," 5 13 1 10 0 8 12 7 12 6 10 6 9 1"," 8 1 9 8 3 7 4 7 6 6 4 2 1 34"}
{530297,855050,171965,944348,720518,473770,206337,204464,316763,716052,814140,7660,23969,816281}
119
Returns: { 425445, 478858, 406360, 544103, 253161, 521751, 377279, 434226, 423138, 480735, 415274, 280142, 318556, 1442586 }
{" 10 11 5 0 3 8 5 7 8 0 11 3 10 2 17"," 8 3 6 2 4 9 5 3 11 1 2 0 9 10 27"," 2 9 1 8 11 6 12 3 12 13 0 10 6 2 5"," 4 2 2 12 7 0 9 5 1 11 12 11 9 0 15"," 8 7 9 12 1 0 11 6 3 10 3 7 3 0 20"," 0 2 8 2 5 13 0 4 12 8 11 0 0 1 34"," 8 5 7 2 2 10 11 0 10 12 1 11 4 5 12"," 8 0 7 10 9 11 10 2 0 1 9 0 11 2 20"," 13 2 3 3 5 7 0 12 1 1 2 4 6 6 35"," 1 5 7 0 6 13 3 11 9 11 12 2 0 8 12"," 9 2 13 2 10 0 1 2 10 3 2 12 11 2 21"," 6 3 7 10 11 13 12 11 6 9 6 5 1 0 0"," 10 5 0 7 5 8 13 0 2 10 7 8 13 8 4"," 4 8 5 6 4 4 3 10 10 0 1 12 10 2 21"," 10 8 6 9 11 2 4 3 4 7 8 7 8 8 5"}
{66844,236569,545552,235911,150172,558291,756131,733454,417249,489844,894348,926876,942750,34552,906438}
8226
Returns: { 560222, 406436, 456300, 461804, 524059, 516676, 503316, 398705, 499301, 531439, 488185, 484799, 527787, 326996, 1208956 }
{" 10 1 8 6 10 3 9 9 8 6 10 2 0 2 8 1 7"," 4 5 0 0 4 4 4 11 11 2 3 8 5 11 2 1 25"," 6 0 10 9 6 0 9 8 6 11 4 4 1 9 7 6 4"," 4 6 3 9 0 8 4 9 0 8 5 6 8 9 7 5 9"," 10 3 5 11 5 4 9 4 5 7 6 7 11 2 2 3 6"," 0 9 2 9 11 4 1 9 1 2 6 1 0 3 6 9 27"," 8 8 7 11 4 6 2 5 6 2 3 1 1 8 11 4 13"," 10 10 11 2 2 7 7 10 6 1 2 5 11 8 8 0 0"," 2 9 9 9 4 2 7 0 3 10 1 9 3 1 2 4 25"," 2 6 6 8 5 1 1 3 10 10 6 2 5 0 2 11 22"," 3 9 3 4 9 7 3 0 4 8 10 6 9 1 0 10 14"," 0 10 1 9 2 0 4 8 6 5 0 6 10 0 0 6 33"," 4 7 4 7 4 10 9 6 1 9 4 1 3 2 0 10 19"," 6 0 3 1 9 0 11 0 0 9 11 11 7 9 0 7 16"," 7 4 10 0 3 7 4 0 1 9 2 5 2 6 10 8 22"," 3 4 1 4 0 1 11 8 11 3 1 11 4 6 0 4 28"," 7 5 9 1 4 5 7 1 7 10 9 10 10 10 5 0 0"}
{40826,478197,941776,323289,27979,15072,409670,597323,654115,602273,130170,988059,491985,203954,767195,120943,189072}
10000
Returns: { 360422, 391163, 398591, 387628, 327536, 283554, 420957, 345456, 375322, 489045, 367659, 414204, 402255, 385890, 285525, 336982, 1009709 }
{"0 1 99","0 100 0","100 0 0"}
{1000000,0,1000000}
10000
Returns: { 99, 1999901, 0 }
{"0 1 99","0 100 0","100 0 0"}
{1000000,0,1000000}
50
Returns: { 777832, 444335, 777833 }
{"7 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ","5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 "}
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
10000
Returns: { 2, 19, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }