Hashing function

---
Last edited on
Um... Just as my opinion, but
Hashing function
and
I have only been doing C++ for 2 weeks.
don't go together.


However, is something like this what you wanted?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int hashCode(string str) {
	int hashcode = 0;
	for( int i = str.length() - 1; i >= 0; i-- )
		hashcode = 31 * hashcode + str[i];
	return hashcode;
}

int main() {
	string s;
	cout << "Enter a string: ";
	getline(cin, s);
	cout << "The hashcode is " << hashCode(s) << endl;
	return 0;
}
I have a semester of Java experience so I'm not completely new to programming itself. I just wanted to tackle this in the new language I'm learning.

Thanks for taking the time to do that, it looks great. I can see what you were doing with it. You're a lifesaver :)
Last edited on
Oi, why'd you delete your original post? Now if someone has the same question, they won't be able to rely on this thread to answer it for them! >:|

-Albatross
Last edited on
closed account (D80DSL3A)
Does anyone think that deleting the starter thread should be a reportable offense? It is abusive.
I would argue that it should be! Once a person knowingly posts something on the internet it's in the public domain, denying others access to it for anyreason is wrong.
Does anyone think that deleting the starter thread should be a reportable offense? It is abusive.


yes yes yes
Annoying and counter-productive? Yes.

Illegal, unethical or preventable? No. Although you could set up your forums so that posts can't be edited, it's a bit restrictive.

What we think of as obnoxious and inconsiderate to the greater good might seem like common sense to those more fearful of displaying their thought to an unknown and uncontrolled audience.

BUT, I'll bet a LOT of this behavior (esp. around here) is due to students attempting to hide their trail of virtual cheating from their teachers prying eyes. 8^O

In this case, though, I'm betting it's just a simple case of csmissunderstanding.

If twicker kept enough space for the history of new users' posts and there was a feature that allowed us to revert a post by a certain number of edits, this would be a non-issue. :/

-Albatross
Last edited on
In this case, though, I'm betting it's just a simple case of csmissunderstanding.


I'm arresting you for crimes against puns. :)
Topic archived. No new replies allowed.