How do I correct the program below to search all the anagrams in a given file.
First, for each word, build another word (its key) with all its letters sorted. For instance, build "dorw" for "word", or "eelttr" for "letter".
Build an array of all the keys, and sort it using a bubble sort. I have to write a modified version of bubble sort that maintains also the array of the primary words.
For instance, if I had ["rude", "word", "dure", "from", "form", "letter"],
our initial array of keys would be:
["deru", "dorw", "deru", "fmor", "fmor", "eelttr"]
After the sort, we should have the keys as:
["deru", "deru", "dorw", "eelltr", "fmor", "fmor"]
and the words
["rude", "dure", "word", "letter", "from", "form"]
I need to go through the array of keys to find out duplicated keys, and the corresponding words. Or how can I do this with struct and arrays? Thanks in advance.
#include <iostream>
#include <fstream>
char** read(const char* fileName, int& count)
{
std::ifstream countingStream( fileName);
// first count them
count = 0;
while (true) {
char line[100];
countingStream. getline(line, 100);
if (strlen(line) == 0) {
break;
}
count += 1;
}
countingStream. close();
std::ifstream readingStream(f ileName);
char** words = new char* [count];
for (int index = 0; index < count; ++index) {
char line[100];
readingStream.g etline(line, 100);
words[index] = strdup(line);
std::cout << line << std::endl;
}
readingStream.c lose();
return words;
}
0 4446 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Gram |
last post by:
Hello,
Can anyone help out with a bubble sort for strings using ASP? I have a text
file of words id like to sort and count.
Thanks in advance for any help.
Gram.
|
by: Mark Kamoski |
last post by:
Hi--
Please help.
I need a code sample for bubble sort.
Thank you.
--Mark
|
by: Chris |
last post by:
I have a bubble sort for a 2-dimensional array that sorts a
string,number pair based on the number. The code for the sort is as
follows:
Private Sub SortArray(ByRef roundarray(,) As String)
Dim i, j, x As Integer
x = roundarray.GetUpperBound(0)
Dim tempname, tempnumber As String
For i = 0 To x - 1
For j = i + 1 To x
|
by: Gaijinco |
last post by:
I'm not quite sure why this code doesn't works:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
class word
{
|
by: scruggsy |
last post by:
Given a dictionary of words, and a phrase, I want to find all possible combinations of words such that their letters form an anagram of the phrase. For instance:
Words: STACK, STICK, I, LIE, ALE, TALE, SICK
Phrase: I LIKE CATS
Anagrams: I LIE STACK, I ALE STICK, TALE I SICK
I've written a function to convert each word to a signature representing the number of times each of its letters appears, in alphabetical order (so SINNING would reduce...
| |
by: sonali deshpande |
last post by:
hi,
i have newly started with C programming.i have been trying a lot for bubble sort.
i want a program that takes words as input and then outputs them alphabetically.
plz help!!
thanx in advance
|
by: midknight5 |
last post by:
Hello everyone, I am familiar with a normal bubble sort when dealing with an array of number but I am unsure as how to implement a sort when I have an array that is filled with classes which hold multiple values.
I need to make a bubble sort that reaches into an array called Tree which has in each storage location a class called Christmas Tree which have the values Species, Height, trunkDiameter, and costPerFoot. The sort will need to sort...
|
by: mahdiahmadirad |
last post by:
Hi dears!
I wrote a simple bubble sort algorithm. it works properly when we compare full arrays but i want to sort a 2d array according to a specific part of array. it has some problem to swapping this array. please help me.
my scenario:
assume that we have a big 2d char array for example students for 20 persons an 30 character for each person. first 15 chars contains first name and the rest is last name.
no i want to sort this array...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |