2008 Canadian Computing Competition, Stage 1
Problem S1: It's Cold Here!
Canada is cold in winter, but some parts are colder than others. Your task is very simple - you need to find the coldest city in Canada. So, when given a list of cities and their temperatures, you are to determine which city in the list has the lowest temperature and is thus the coldest.
The input is a sequence of city names and temperature values. Temperatures are integer, possibly preceded with a minus sign. There is a single space between the city name and the temperature. No city name contains any whitespace and is always less than 256 characters in length. There is at least one city in the list, no more than 10000 cities, and the last city is always Waterloo. You may assume that the temperature is not less than -273 and not more than 200.
OutputYou are to output the name of the coldest city on a single line with no whitespace before or after the name. You may assume that there will not be more than one city which is the coldest.
Saskatoon -20 Toronto -2 Winnipeg -40 Vancouver 8 Halifax 0 Montreal -4 Waterloo -3
Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 28, 2008
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
(Try adding right before to see what I mean.)
It takes the string s and tries converting it into a number, held by v. If it fails, it stores the position of the failure in code. (If it succeeds, Code is set to zero.)
Add the snippet I asked you to attach to your code and run it against the sample data. What is the problem?
thnx to brian
Ur Awesome :) btw, wat grade r u in?
It's actually much simpler to code this way, too.
Also, an array of 10000 strings won't compile in Turbo Pascal - that uses too much memory. An array of 200 strings would fit, though.
Basically it's because C++ strings are slow.
the reason you can't do something like this (It's been while since I coded in pascal),
is because PAscal doesn't not recognize spaces as "separation" between input for strings, so youw ould end up with the whole input line in one string.