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 Working
Posted by: Aaron | November 19, 2010 @ 1:26am
C++ Code
[
Download
]
#include <iostream> #include <string> using namespace std; bool isAnagram(const string &s1, const string &s2); int main () { string one("god"); string two("dog"); isAnagram(one,two); system("pause"); return 0; } bool isAnagram(const string &s1, const string &s2) { int countsA[256]; for (int i = 0; i < 256; i++) { countsA[i] = 0; } int iCountOne = s1.length(); for (int i = 0; i < iCountOne; i++) { countsA[s1.at(i)]++; } int sumOne = 0; for (int i = 0; i < iCountOne; i++) { sumOne = sumOne + countsA[i]; } int countsB[256]; for (int i = 0; i < 256; i++) { countsB[i] = 0; } int iCountTwo = s2.length(); for (int i = 0; i < iCountTwo; i++) { countsB[s2.at(i)]++; } int sumTwo = 0; for (int i = 0; i < iCountTwo; i++) { sumTwo = sumTwo + countsB[i]; } if (sumOne == sumTwo) { cout << "ANAGRAM"; return true; } else { cout << "NOT ANAGRAM"; return false; } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.55 / 8
33 Votes
http://codebin.yi.org/962
page generated in 0.01 seconds