Is cin/cout slower than scanf/printf ?

There are few potential pitfalls with cin/cout :

  • By default, cin/cout waste time synchronizing themselves with the C library’s stdio buffers, so that you can freely intermix calls to scanf/printf with operations on cin/cout. Turn this off with std::ios_base::sync_with_stdio(false);
  • Many C++ tutorials tell you to write cout << endl instead of cout << '\n'. But endl is actually slower because it forces a flush, which is usually unnecessary. (You’d need to flush right before prompting the user for input from cin, but not when writing a million lines of output.) Write '\n' instead of endl.
  • There was a bug in very old versions of GCC (pre-2004) that significantly slowed down C++ iostreams. Don’t use ancient compilers.

Avoid these pitfalls, and cin/cout will be just as fast as scanf/printf. My benchmarks indicate that cin/cout is actually 5%–10% faster.

Rename files in a directory randomly

Using Terminal – 

Go to that folder and run the following : 


for file in *.txt ; do
   name=$(tr -dc "[:alnum:]" < /dev/urandom | head -c 10)
   mv "$file" ${name}.txt

instead of “.txt” any other extension may be used.
We can change :alnum: to :digit: or :alpha: depending on what we want.

Installing Apache, PHP and MySQL on Ubuntu 13.04

1. Update.
sudo apt-get update

2. Install Apache
sudo apt-get install apache2

3. Check if Apache is running, navigate to http://localhost/

4. Install PHP
sudo apt-get install php5 libapache2-mod-php5

5. Restart Apache
sudo service apache2 restart

6. Check to make sure PHP has successfully installed
cd /var/www/
sudo rm index.html
sudo nano index.php

– Now type, inbetween php tags;
echo phpinfo();

7. Install MySQL
sudo apt-get install mysql-server php5-mysql

8. Install phpMyAdmin
sudo apt-get install phpmyadmin

9. Edit the Apache Configuration file
sudo nano /etc/apache2/apache2.conf

10. Add the following line to the end of the file;
Include /etc/phpmyadmin/apache.conf

11. Link phpMyAdmin to the /var/www/ directory
sudo ln -s /usr/share/phpmyadmin /var/www/

12. AllowNoPassword (Optional, only if you set the mysql password to nothing.)
sudo nano /etc/phpmyadmin/

13. Uncomment the following line in;
$cfg[‘Servers’][$i][‘AllowNoPassword’] = TRUE;

14. Restart Apache
sudo service apache2 restart

Indian Computing Olympiad

conducted by the Indian Association for Research in Computing Science in coordination with CBSE

Ref. Links :