قُلْ إِنَّ صَلَاتِي وَنُسُكِي وَمَحْيَايَ وَمَمَاتِي لِلَّـهِ رَبِّ الْعَالَمِينَ - الأنعام: ١٦٢

Showing posts with label UVa. Show all posts
Showing posts with label UVa. Show all posts

Wednesday, September 30, 2009

Problem Solving

السلام عليكم و رحمة الله و بركاته

I came through three interesting links yesterday. May be they are common, I'm not really sure.
Here they are..

-UVA toolkit
Here you can browse for a problem, write the Input & it generates the output for you.
Perfect for testing when you think you have the problem right :)
It also links you to the problem statement and the statistics of the problem.


Here, there are 2 useful links
  • C programming basic
  • Algorithm
  • Math puzzle
  • IQ
where you can check the source codes of some problems.


If you navigated to the "UVa" on the left side, you can choose a volume and browse for problems.
Then you can check the category & difficulty of your problem.
If you chose a specific problem, you get some hints for it & sometimes the code is available too.

Monday, September 28, 2009

Detecting the "Enter" key

السلام عليكم و رحمة الله و بركاته

This is a short post.
almost a year ago, I tried to solve a problem on the UVa and i got it "Time limit exceeded". I knew before submitting that it won't be accepted, as i didn't know how to detect the "Enter" key press and it was needed as a stop condition for the first loop :D

anyway, here we go
if you are trying to use "cin" then you'll not be able to detect the new line.
when debugging, u may enter 10 new lines & then a value...i mean it will wait for the value and won't consider the new lines!

you may go to a lower level
if(cin.get() == '\n')
but that's when u are expecting the enter to be pressed
as it reads 1 char only

or u can use "cin.getline()"
and then check for the string's length
if == 0 then "Enter" is pressed
That's useful when u r expecting a mix of strings & enters


sources:
ACMaa Magdi (thanks :))