Exchanging

Discuss Computer Science and Programming related problems

Moderators:Labib, bristy1588

Hasib
Posts:238
Joined:Fri Dec 10, 2010 11:29 am
Location:খুলনা, বাংলাদেশ
Contact:
Exchanging

Unread post by Hasib » Fri Dec 24, 2010 10:25 pm

It's a nice problem. If u want to exchange the value of two variable a & b, u may go like this:

int a,b,c;
c=a;
a=b;
b=c;

but, i asked to do it without having an another variable. :)
A man is not finished when he's defeated, he's finished when he quits.

HandaramTheGreat
Posts:135
Joined:Thu Dec 09, 2010 12:10 pm

Re: Exchanging

Unread post by HandaramTheGreat » Sat Dec 25, 2010 10:12 am

a^=b^=a^=b; ;)

AntiviruShahriar
Posts:125
Joined:Mon Dec 13, 2010 12:05 pm
Location:চট্রগ্রাম,Chittagong
Contact:

Re: Exchanging

Unread post by AntiviruShahriar » Sat Dec 25, 2010 12:03 pm

HandaramTheGreat wrote:a^=b^=a^=b; ;)
এইটা কি লেখলা আপু??? চট্টগ্রামে কি গনিত কর্মশালা হচ্ছে??? আমি আর রাফিদ একজনো কর্মশালার খবর জানিনা :cry:

HandaramTheGreat
Posts:135
Joined:Thu Dec 09, 2010 12:10 pm

Re: Exchanging

Unread post by HandaramTheGreat » Sat Dec 25, 2010 12:17 pm

AntiviruShahriar wrote:এইটা কি লেখলা আপু???
^ মানে XOR(exclusive OR)
a=a^b;
b=b^a;
a=a^b;
এইটার শর্ট ফরম হইল উপরেরটা... ভ্যালু বসাই দেখ, বুঝবা...
চট্টগ্রামে কি গনিত কর্মশালা হচ্ছে??? আমি আর রাফিদ একজনো কর্মশালার খবর জানিনা :cry:
আমারে জিগায়া কাম নাই, আমি বর্তমানে নির্বাসিত জীবনযাপন করতেসি, বহুদিন পরপর গুহা থেইক্যা বাইর হই...কোনরকমে এমও-র রেজি. কইরা আসছি মাত্র... :cry: তবে পরশুর পেপারে দেখসি সিএমসি-র সভা হওয়ার কথা ছিল গতকাল... আর কিছু জানি না...

AntiviruShahriar
Posts:125
Joined:Mon Dec 13, 2010 12:05 pm
Location:চট্রগ্রাম,Chittagong
Contact:

Re: Exchanging

Unread post by AntiviruShahriar » Sat Dec 25, 2010 2:57 pm

বহুদিন পরপর গুহা থেইক্যা বাইর হই.[/quote]
f.b একাউন্ট বন্ধ নাকি??? অইখানে কথা বলা যাবে...। এইখানে কম discuss ই ভাল...। থাকলে shahriar.md.04@gmail.com এ রিকুএস্ট পাঠাও...। বাই।

HandaramTheGreat
Posts:135
Joined:Thu Dec 09, 2010 12:10 pm

Re: Exchanging

Unread post by HandaramTheGreat » Sat Dec 25, 2010 5:40 pm

btw, exchanging algorithm is usually called 'swap'... :)

sakib
Posts:20
Joined:Tue Dec 07, 2010 3:33 pm

Re: Exchanging

Unread post by sakib » Sun Dec 26, 2010 12:02 am

This is a very nice and easy problem.It was a problem in the dhaka divional informatics olympiad 2010.I got it at that time.Here is my solution is white.(please dont look at it at once,give it a try.It's one of the most simple question you will ever get.


a=a+b;
b=a-b;
a=a-b;

HandaramTheGreat
Posts:135
Joined:Thu Dec 09, 2010 12:10 pm

Re: Exchanging

Unread post by HandaramTheGreat » Sun Dec 26, 2010 1:05 pm

nice and easy tactic... :)

@sakib vaia, can problems of BdOI be found anywhere?

sakib
Posts:20
Joined:Tue Dec 07, 2010 3:33 pm

Re: Exchanging

Unread post by sakib » Sun Dec 26, 2010 1:54 pm

The kind of exam we have in BDOI in actually not that much of a programming contest.
In last year divisional we were given mathematical puzzle type problems which were related to programming basics,but they were not that much of a programming contest.
In the national we were given programming problems,but we just had to write it in our pc and it was checked manually to check how good the algorithm was.
But for the team selection for IOI some online contest would be held.If you want to prepare for BDOI you must start learning programming.There are various site.The best place to start is usaco.(search usaco training and usaco contest in google).I will write a topic about usaco soon.
I dont know if there's any link to previous year's question.

User avatar
Zzzz
Posts:172
Joined:Tue Dec 07, 2010 6:28 am
Location:22° 48' 0" N / 89° 33' 0" E

Re: Exchanging

Unread post by Zzzz » Sun Dec 26, 2010 2:23 pm

I have posted the problemset of last year Here
Every logical solution to a problem has its own beauty.
(Important: Please make sure that you have read about the Rules, Posting Permissions and Forum Language)

Post Reply