Week 2

 During week 2 I did some more same difficulty problems but oddly couldn't submit them through the website, but I'm sure they work. First Problem is taking the "long" words and shorting. This was pretty easy I just took in a number (n) then if I looked at the "next"(String) and checked if the its between the length of 1-100 characters, then if it was more than 10 in length and if it was I would then Print first letter, the number of letters between the first and last, and then the last letter. Pretty easy but I was confused on format because I thought I was suppose to make it so that it would take the 4 inputs and then output them. But I figured out that you can copy the whole input and you'll get the desired output. 

Code down below


For the second problem, I need to take lines of ints, which have 3 numbers that dictate the certainty of three people 1 being certain and 0 being uncertain. So I did a nested for loops to go through array of numbers and made counts to count the ones in each row and if the count of ones was 2 or more then, I would add to the output count, which means they would write the solution. At first It reminded me of a homework assignment I did for csc 240 where I would read in a file that had 20 lines with 3 numbers on each line and you would decided if the numbers make a perfect triangle. The challenging part was they took those numbers as string ,so what I had to do what cut the string up to each space and convert the string into int save each of the numbers check if they make a perfect square then move to the next line. Keeping that in mind, I tried to do that for this code but I couldn't figure out how to do it because the assignment that I did was C. I figured out I was just making it much harder because I didn't need to take in the numbers as string and that made things much simpler.

Code down below






Comments

  1. Interesting work. For the first problem, I too can relate to being confused about formatting. Sometimes the problem itself is not hard, but the formatting can throw you off. For the second problem, I do not have much to ask since it's straight forward. I can it's application for maybe surveys. Also, sometimes the answers can be obvious. I've had a somewhat similar experience in MATLAB where I write in the numbers as strings in a cell (similar to matrices in that it organizes values into rows and columns but distinct in that it you can put any character array) using the num2str function, only to find out that character arrays in separate cells did not need to match, and I just had to type in the numerical value. The answer can be simple at times. Anyways, great work!

    ReplyDelete

Post a Comment

Popular posts from this blog

Week 9

Week 10

Week 11