submit p1prFinal p1prFinal.cpp
submit p2prFinal p2prFinal.cpp
submit p3prFinal p3prFinal.cpp
inA.txt colors in original order |
inA.txt colors ordered by brightness |
|
|
CornflowerBlue 100,149,237 #6495ED ---------- | | | ------- name red | blue hex green... where the only spaces are beween the name and the rgb triple, and between the rgb triple and the hex value. The rgb values are integers in the range 0..255 inclusive. The first line of the file is of the form
N=number
, where number is
the number of colors listed in the file.
Your program should print out the colors in order of decreasing brightness, where brightness is defined as the average of the rgb values. In the above example, CornflowerBlue has an brightness of (100+149+237)/3 = 162.0. Black (rgb value 0,0,0) has brightness 0, so it is the least bright color possible ... which should make some sense. If colors have the same brightness, they should appear alphabetically by name.
Note: here are some input files: inA.txt, inB.txt, inC.txt, inD.txt, inE.txt.
S A M P L E R U N S | |||
~/$ ./p1 > inA.txt LightYellow 255,255,224 #FFFFE0 Gainsboro 220,220,220 #DCDCDC Aqua 0,255,255 #00FFFF DarkGray 169,169,169 #A9A9A9 Tomato 255,99,71 #FF6347 YellowGreen 154,205,50 #9ACD32 DimGray 105,105,105 #696969 |
~/$ ./p1 > inE.txt Ivory 255,255,240 #FFFFF0 MintCream 245,255,250 #F5FFFA Lavender 230,230,250 #E6E6FA LemonChiffon 255,250,205 #FFFACD LightGoldenRodYellow 250,250,210 #FAFAD2 Cyan 0,255,255 #00FFFF Fuchsia 255,0,255 #FF00FF Magenta 255,0,255 #FF00FF |
~/$ ./p1 > inB.txt Lavender 230,230,250 #E6E6FA LightGoldenRodYellow 250,250,210 #FAFAD2 BlanchedAlmond 255,235,205 #FFEBCD Pink 255,192,203 #FFC0CB PaleGoldenRod 238,232,170 #EEE8AA LightSkyBlue 135,206,250 #87CEFA Silver 192,192,192 #C0C0C0 PaleGreen 152,251,152 #98FB98 Orchid 218,112,214 #DA70D6 SandyBrown 244,164,96 #F4A460 RosyBrown 188,143,143 #BC8F8F SlateBlue 106,90,205 #6A5ACD SpringGreen 0,255,127 #00FF7F DarkSlateBlue 72,61,139 #483D8B SeaGreen 46,139,87 #2E8B57 Brown 165,42,42 #A52A2A |
~/$ ./p1 > inC.txt Ivory 255,255,240 #FFFFF0 LavenderBlush 255,240,245 #FFF0F5 BlanchedAlmond 255,235,205 #FFEBCD NavajoWhite 255,222,173 #FFDEAD Wheat 245,222,179 #F5DEB3 Plum 221,160,221 #DDA0DD SkyBlue 135,206,235 #87CEEB Orchid 218,112,214 #DA70D6 MediumTurquoise 72,209,204 #48D1CC Tomato 255,99,71 #FF6347 DarkOrchid 153,50,204 #9932CC SlateBlue 106,90,205 #6A5ACD MediumVioletRed 199,21,133 #C71585 RebeccaPurple 102,51,153 #663399 DarkCyan 0,139,139 #008B8B DarkSlateGray 47,79,79 #2F4F4F |
xnew = (xold * a) % bSo, for example, if a = 58 and b = 72
step 1 step 2 step 3 step 4 step 5 step 6 58 -----------> 52 -----------> 64 -----------> 40 -----------> 16 -----------> 64 -----------> 40 -----------> ... (58*58)%72 (52*58)%72 (64*58)%72 (40*58)%72 (16*58)%72 (64*58)%72 i.e. 58*a % b 52*a % b 64*a % b 40*a % b ...For this problem, we want to know how many "steps" it takes until we see our first repeated value. So, for the example a = 58 and b = 72 shown above, we see that after 5 steps we see our first repeated value (64).
Write a program p2prFinal.cpp that reads integers a and b,
1 < a < b, and prints out the number of steps of the
above process until the first repeated value is seen.
NOTE: You may make no assumptions about the number of steps that
will be required!
S A M P L E R U N S | ||||
~/$ ./p2 > 58 72 repeat after 5 steps |
~/$ ./p2 > 12 89 repeat after 8 steps |
~/$ ./p2 > 3 17 repeat after 16 steps |
~/$ ./p2 > 7971 13977 repeat after 777 steps |
~/$ ./p2 > 5 13977 repeat after 4656 steps |
with a = 2, b = 15 initial = 2 step 1 -> 4 step 2 -> 8 step 3 -> 1 step 4 -> 2 1st repeat is 2 |
with a = 2, b = 16 initial = 2 step 1 -> 4 step 2 -> 8 step 3 -> 0 step 4 -> 0 1st repeat is 0 |
with a = 2, b = 20 initial = 2 step 1 -> 4 step 2 -> 8 step 3 -> 16 step 4 -> 12 step 5 -> 4 1st repeat is 4 |
with a = 5, b = 7 initial = 5 step 1 -> 4 step 2 -> 6 step 3 -> 2 step 4 -> 3 step 5 -> 1 step 6 -> 5 1st repeat is 5 |
4 accounts 87623 Joe Cool $890.76 45672 Dan Roche $123.45 98783 Ric Crabbe $1209.78 67878 Chris Brown $72.48
show acctNum
transfer $amount acctNum1 to acctNum2
S A M P L E R U N S | |
~/$ ./p3 inX.txt > show 45672 45672 Dan Roche $123.45 > show 67878 67878 Chris Brown $72.48 > show 31415 Error! > transfer $100 45672 to 67878 > show 45672 45672 Dan Roche $23.45 > show 67878 67878 Chris Brown $172.48 > transfer $100 45672 to 67878 Dan Roche is bankrupt! |
~/$ ./p3 inY.txt > transfer $200 223 to 198 Error! > show 223 Error! > show 222 222 Aretha Franklin $387.87 > transfer $200 222 to 198 > show 222 222 Aretha Franklin $187.87 > transfer $200 222 to 198 Aretha Franklin is bankrupt! |