• Welcome to Valhalla Legends Archive.
 

Quick Question

Started by Dyndrilliac, April 21, 2004, 08:46 AM

Previous topic - Next topic

Eli_1

Quote from: Dyndrilliac on April 21, 2004, 02:14 PM
(Like II is the Logical OR, I wanted to know the equivalent of II for the Exclusive OR)

Logical OR is ||, not ii.

Dyndrilliac

My mistake - I was typing quickly and since they looked simlar didn't catch that.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

iago

Quote from: Dyndrilliac on April 21, 2004, 02:42 PM
My mistake - I was typing quickly and since they looked simlar didn't catch that.

Easy mistake to make.  I was going to point that out too :)

So, is your question answered?  I don't know if my code works or not, but I'm a little curious :)

If you also want to *generate* random numbers, not get them from the keyboard, that will take a little more.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Dyndrilliac

#18
Basically, yes, my question was answered, thanks :)

However, I don't have MSVC++ on my laptop so I'll have to wait until I get home to try it.

And inputting them is fine, I already learned how to use random numbers using the computer clock time as my seed value.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Mephisto

#19
Quote from: Dyndrilliac on April 21, 2004, 08:46 AM
Edit: Also, does anyone know what symbols to use for the exclusive or logical operator? I _think_ that is what it's called (xor in VB and ASM), where one or the other can be true for the statement to be true but not both.

No, I do think you're mixed up.  There's no such thing as an exclusive or logical operator.  There's only exclusive or and logical or, unless I'm mistaken.  And when you say you think it's xor in VB and ASM (correct) you describe the logical or, and not the exclusive or.  That's why I think you're mixed up.  Correct me if I'm wrong.

Edit: Ahh, nevermind.  I see now, thanks to iago.  Sorry about that Dynrilliac...This is why I dislike trying to read people's statements that are confusing and badly written.

MyndFyre

Quote from: Mephisto on April 21, 2004, 09:30 AM
Quote from: Dyndrilliac on April 21, 2004, 08:46 AM
Edit: Also, does anyone know what symbols to use for the exclusive or logical operator? I _think_ that is what it's called (xor in VB and ASM), where one or the other can be true for the statement to be true but not both.

I believe you're mixed up.

xor in languages which support bitwise operators is excluseive OR.
In C/C++ the bitwise operator xor is ^ and it compares two operand's bits, and if the corresponding operands are different (e.g. 0 and 1) then the corresponding bit is set to 1.  If they are the same, the corresponding bit is set to 0.  Think of it as if both bits are different when you xor them, the return is 1, and if they are the same, the return is 0.  You can use the xor (^) by including the iso646.h library or compile with the disable language extensions compiler option (/Za).  Though you should simply beable to use it without doing anything on most modern compilers.

or is the logical operator of "or" in programming languages.  In C/C++ the operator identifier is ||.  When two operands are compared with logical OR the result is a boolean value of true if at least one operand evaluates to true.  If both operands evaluate to false, then the boolean value returned is 0.  It should be noted that before the test begins, each operand is implicitly converted to bool.
Quote

The "Boolean Logical" exclusive OR is pretty cool -- basically, if an odd number of operands are true, then it returns true, otherwise false.

As iago pointed out, XOR in C++ is ^and ^=.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Dyndrilliac

Quote from: Mephisto on April 21, 2004, 06:20 PM
Quote from: Dyndrilliac on April 21, 2004, 08:46 AM
Edit: Also, does anyone know what symbols to use for the exclusive or logical operator? I _think_ that is what it's called (xor in VB and ASM), where one or the other can be true for the statement to be true but not both.

No, I do think you're mixed up.  There's no such thing as an exclusive or logical operator.  There's only exclusive or and logical or, unless I'm mistaken.  And when you say you think it's xor in VB and ASM (correct) you describe the logical or, and not the exclusive or.  That's why I think you're mixed up.  Correct me if I'm wrong.

Edit: Ahh, nevermind.  I see now, thanks to iago.  Sorry about that Dynrilliac...This is why I dislike trying to read people's statements that are confusing and badly written.

http://www.starlink.rl.ac.uk/star/docs/sun95.htx/node412.html

Logical Exclusive OR Operator. Excuse me for reversing 2 words.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Mephisto

#22

#include <iostream>
#include <set>
int main() {

   typedef std::set<int> ISet;
   ISet num;
   
   for (int i = 0, temp; i < 10 && std::cin >> temp; ++i) {
       num.insert(temp);
   }
   
   ISet::const_iterator it;
   
   for (it = num.begin(); it != num.end(); ++it) {
       std::cout << *it << ' ';
   }
   
   std::cout << std::endl;
   return 0;
}

That may be easier and more efficient to use than Eibro's vector.  The set will require you to insert values into the set (using the member function) and then use an iterator to scan through the set and get what you need shown in the second loop.
This code is also untested, and I've had problems using templates and STL classes/containers on GCC/G++ so if you are using that (Dev-CPP is an IDE for GCC/G++ IIRC) then it may not work as expected.  Compiling on Microsoft's compilers should work however. If it does not work then you might try something more manual which generally works for me on GCC:


#include <iostream>
#include <set>
int main() {

   typedef std::set<int> ISet;
   ISet num;
   
   /* this is the loop which accomplish what the next 12 lines do.  This is generally where gcc screws up for me.
   for (int i = 0, temp; i < 10 && std::cin >> temp; ++i) {
       num.insert(temp);
   } */
   int a, b, c, d, e, f, g, h, i, j;
   std::cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j;
   num.insert(a);
   num.insert(b);
   num.insert(c);
   num.insert(d);
   num.insert(e);
   num.insert(f);
   num.insert(g);
   num.insert(h);
   num.insert(i);
   num.insert(j);
   
   ISet::const_iterator it;
   
   for (it = num.begin(); it != num.end(); ++it) {
       std::cout << *it << ' ';
   }
   
   std::cout << std::endl;
   return 0;
}


Note, that because this uses a regular set, you cannot have the same of two values.  So if you enter two 2s, you will only get one back when it's displayed.  You can use a multiset to accomplish having more than one of the same values.  All you need to do to do this is simply replace set with multiset and basically the same functionality that you see applys.