The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Anagram Final
Posted by: Aaron | November 19, 2010 @ 2:07am
C++ Code
[
Download
]
#include <iostream> #include <string> using namespace std; bool isAnagram(const string &s1, const string &s2); int main () { string one(" "); string two(" "); cout << "ENTER FIRST WORD: " << '\n'; cin >> one; cout << "ENTER SECOND WORD: " << '\n'; cin >> two; if(isAnagram(one,two)) { cout << "ANAGRAM"; } else { cout << "NOT ANAGRAM"; } cout << endl; system("pause"); return 0; } bool isAnagram(const string &s1, const string &s2) { int countsA[256]; int countsB[256]; int iCountOne = s1.length(); int iCountTwo = s2.length(); //set arrays to zero for (int i = 0; i < 256; i++) { countsA[i] = 0; countsB[i] = 0; } for (int j = 0; j < iCountOne; j++) { countsA[j] = s1.at(j); } int sumOne = 0; for (int k = 0; k < iCountOne; k++) { sumOne += countsA[k]; } for (int l = 0; l < iCountTwo; l++) { countsB[l] = s2.at(l); } int sumTwo = 0; for (int m = 0; m < iCountTwo; m++) { sumTwo += countsB[m]; } if(sumOne == sumTwo) { return true; } else { return false; } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.65 / 8
26 Votes
http://codebin.yi.org/965
page generated in 0.00 seconds