Skip to content

Instantly share code, notes, and snippets.

@LizardLeliel
Last active August 29, 2015 13:59
Show Gist options
  • Save LizardLeliel/10561152 to your computer and use it in GitHub Desktop.
Save LizardLeliel/10561152 to your computer and use it in GitHub Desktop.
Dalhousie problem letter B.
#This was Dalhousie Programming Competition 2014 programming problem letter B.
#I found that the 2d lists (Python doesn't have 2d arrays; they have things called lists, similar to arrays, but only one dimensional...
#you had to have lists in lists to have dimensionality) I've used while programming an older Sudoku program of mine to be helpful
#This Problem had a varying ammount of inputs. The first input was how many inputs was going to follow,
#While all lines after that were in the format "name ##". The ## was a number between 1 and 100, an represents
#The mark of each name. The names were useless, but I was suposed to make a histogram based on how many people
#Got Something in the tens digit. In other words...
# 6
#Leliel 95
#Sufisant 84
#Chiaro 92
#Razgriz 74
#Fallmond 75
#Melchior 71
#And the output was:
# +----------+
#5| |
#4| |
#3| * |
#2| * * |
#1| *** |
# +----------+
#I initalize some values and store data
grades = []
length = int(str(raw_input()))
for each in range(length):
appendthis = int(raw_input().split(" ")[1])
grades.append(appendthis)
if each >= length: break
decimal = []
for thing in grades:
decimal.append(thing/10)
#I started programming things in related to outputing the data has a historgram
q = " +-----------+"
col0 = []
col1 = []
col2 = []
col3 = []
col4 = []
col5 = []
col6 = []
col7 = []
col8 = []
col9 = []
col10 = []
colall = [col0, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10]
#I populated some of the values above and did functions on them to make them ready to output
for number, each in enumerate(colall):
for thing in decimal:
if number == thing: each.append("*")
for each in colall:
while len(each) != 5:
each.append(" ")
for each in colall:
each = reversed(each)
#I prepared the histogram datas as strings instead of lists in these functions I used in final output
def row1(colall):
string = ""
for each in colall:
string = string+each[4]
return string
def row2(colall):
string = ""
for each in colall:
string = string+each[3]
return string
def row3(colall):
string = ""
for each in colall:
string = string+each[2]
return string
def row4(colall):
string = ""
for each in colall:
string = string+each[1]
return string
def row5(colall):
string = ""
for each in colall:
string = string+each[0]
return string
#I output my data
print (q)
print ("5|"+row1(colall)+"|")
print ("4|"+row2(colall)+"|")
print ("3|"+row3(colall)+"|")
print ("2|"+row4(colall)+"|")
print ("1|"+row5(colall)+"|")
print (q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment