OK, this is a pretty weird question, but shouldn't be to hard to
accomplish. Remember, I am a beginner so please, if I say something
stupid, be gentle. :-)
I do not know vectors yet, which would probably be a better idea than
an array for this, but I want to try using an array for now and then
will update it once I learn vectors. I havent really learned arrays
yet either.... :-)
So here it is.... I want to read in a string of characters into an
array. Then take that string of letters and remove all double +
letters. Meaning, you type in BLURRY and you end with BLURY (there
were two R's so one is removed). Then, I want to mix them all up.
So, three main stages. 1. Input 2. Remove doubles - tripples - ect.
and 3. Mix em up.
The input is pretty easy. I could use a for loop but then I would have
to have a set number of input characters, correct? I am using this
right now.....
char x = 'a';
int y = 0;
while ( a != '*' )
{
cin >> arrayname[y];
y++;
}
So they would input the characters until they were done and then add *
at the end. Then I can just discard the last entry into the array.
That will pull in my characters.
Now, no idea how I will remove like items. Maybe feed each element
into a new array and check for doubles as I go? Any good ideas here?
Then, how to mix them up.... I was thinking of using the srand and
rand to generate a random number based off an entered seed number and
grab that element number from the first array and insert it in order
in a new array.
So, how bad have I screwed up the logic on this one? :-) 3 2642
da Vinci wrote: OK, this is a pretty weird question, but shouldn't be to hard to accomplish. Remember, I am a beginner so please, if I say something stupid, be gentle. :-)
I do not know vectors yet, which would probably be a better idea than an array for this, but I want to try using an array for now and then will update it once I learn vectors. I havent really learned arrays yet either.... :-)
Then you should better start with a vector and later go on to arrays. So here it is.... I want to read in a string of characters into an array. Then take that string of letters and remove all double + letters. Meaning, you type in BLURRY and you end with BLURY (there were two R's so one is removed). Then, I want to mix them all up.
So, three main stages. 1. Input 2. Remove doubles - tripples - ect. and 3. Mix em up.
The input is pretty easy. I could use a for loop but then I would have to have a set number of input characters, correct? I am using this right now.....
char x = 'a'; int y = 0;
while ( a != '*' ) { cin >> arrayname[y]; y++; }
So they would input the characters until they were done and then add * at the end. Then I can just discard the last entry into the array.
You also have to check that y doesn't get bigger than the size of the
array - 1.
That will pull in my characters.
Now, no idea how I will remove like items. Maybe feed each element into a new array and check for doubles as I go? Any good ideas here?
Possible. You could also do the same without copying to a new array,
i.e. you can reuse your array for the result.
Then, how to mix them up.... I was thinking of using the srand and rand to generate a random number based off an entered seed number and grab that element number from the first array and insert it in order in a new array.
look up std::random_shuffle.
So, how bad have I screwed up the logic on this one? :-)
da Vinci wrote: I do not know vectors yet, which would probably be a better idea than an array for this, but I want to try using an array for now and then will update it once I learn vectors. I havent really learned arrays yet either.... :-)
If you don't know either, start with vectors.
Brian Rodenborn
On Wed, 29 Oct 2003 00:17:12 +0000, da Vinci wrote: OK, this is a pretty weird question, but shouldn't be to hard to accomplish. Remember, I am a beginner so please, if I say something stupid, be gentle. :-)
I do not know vectors yet, which would probably be a better idea than an array for this, but I want to try using an array for now and then will update it once I learn vectors. I havent really learned arrays yet either.... :-)
So here it is.... I want to read in a string of characters into an array. Then take that string of letters and remove all double + letters. Meaning, you type in BLURRY and you end with BLURY (there were two R's so one is removed). Then, I want to mix them all up.
A linked list would probably be a more efficient data structure to use for
this task. Arrays and similar structures (like vectors) are great for
random access, but if you are going to be inserting and removing elements
frequently, some thing like a linked list is more efficient. The Standard
Library has a linked list in it. You might want to look into it ... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: 2mc |
last post by:
Generally speaking, if one had a list (from regular Python) and an
array (from Numerical Python) that contained the same number of
elements, would a While loop or a For loop process them at the...
|
by: csx |
last post by:
Hi everyone!
two quick questions relating to arrays.
Q1,
Is it possible to re-assign array elements?
int array = {{2,4}, {4,5}};
array = {2,3}
|
by: Taylor Howell |
last post by:
Hello all,
I have a delima. I have 8 5bit numbers that I need to pack into one (or
more) variables. They then must be written (exactly 40bits (5Bytes)) to a
file and have the ability to be put...
|
by: David Cleaver |
last post by:
Hello all,
I was wondering if there were some sort of limitations on the "if"
statement? I'm writing a program which needs to check a bunch of
conditions all at the same time (basically). And...
|
by: Nikolay Petrov |
last post by:
I have a couple of byte arrays.
What is the most efficient way to combine them?
After combining they will go in a network stream.
thanks
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
by: Jeff |
last post by:
In the function below, can size ever be 0 (zero)?
char *clc_strdup(const char * CLC_RESTRICT s)
{
size_t size;
char *p;
clc_assert_not_null(clc_strdup, s);
size = strlen(s) + 1;
|
by: Steven Watanabe |
last post by:
I know that the standard idioms for clearing a list are:
(1) mylist =
(2) del mylist
I guess I'm not in the "slicing frame of mind", as someone put it, but
can someone explain what the...
|
by: felixnielsen |
last post by:
If im not mistaken, a char variable allocates 1 byte of memory, as it
is the case with a bool variable.
I need 2 bool and 1 char variable which only need to contain a value
between 0 and 63...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
|
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...
|
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,...
| |