Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Problem: Character count
INPUT: A word and count all characters appearing consecutively.
OUTPUT: The number of characters appearing consecutively and the letters
Sample Run:
Enter string: Mississippi
3
ssp
Enter string: Committee
3
mte
Enter string: mmmmrrnzzz
4
mmrz
Im a first year college student taking Bachelor of Science in Computer Science. Im hoping you can help me for this problem Thank you :)
There are many ways to solve this problem, but probably the best way for a first year student is to use a loop to solve it.
I don't want to give to many details as that defeats the purpose of the exercise, but the basic process might look something like this:
Treat the string as an array of characters. So the word committee is really c o m m i t t e e. Create a variable to hold the max repeat count, current repeat count and repeat letters. Also create a variable for the current letter and initialize it to "".
for each letter in the input string
does this letter match the value in current_letter?
if yes
increment the current_repeat_count variable
append the current_letter to the repeat_letters array
if current_repeat_count > max_repeat_count
max_repeat_count = current_repeat_count
else
current_letter = the letter you just tested
current_repeat_count = 0
I hope that gets you started.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an array like this
int numbers[]={5,6,5,8,9,1,-6516,8,811,981,981};
and I need to print them to screen with spaces in front of them so the total number of characters printed will be 4. si the number 5 will be printed as 3 spaces and 5 5 the number 811 will be 811 and so on.
As was previously mentioned in comments, this is something you can do with printf. I'm reluctant to write the code because a) it looks like homework and b) you'll have this nailed once you've read up on printf. (You'll need to put that printf in a for-loop to go thru the array, for sure, so read up on for as well if you need to.)
Some good resources for printf are whatever textbook you're using, plus
https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm
https://www.dummies.com/programming/c/how-to-format-with-printf-in-c-programming/
http://www.cplusplus.com/reference/cstdio/printf/ (a reference, not a tutorial)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am using fgets to get a sentence from the user and i am trying to get words and count on c code then print it.
Exapmle: i want to count "Hello". When the program starts user write "Hello World Hello" and then the program prints "Hello used 2 times".
You could use the scanf-function to get text input from the user; the function will put it into a char array. (You would ask the user for the sentence as well as the word you are looking for)
Then you could use the KMP-algorithm to search for the given word in the sentence and just count the times the algorithm finds your word.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a different version of "Split into Words" or "Word Break" problem in dynamic programming. I know the "Word Break" but couldnt adapt it into following problem:
You are given a text (max 200 characters) from a file and required to split the word into 3 parts, each will contain minimum 1 vowel.
For example, for the following text: bcaeiouxtz , we can have 6 possibilities:
bca eio uxtz
bca ei ouxtz
bca e iouxtz
bcae io uxtz
bcae i ouxtz
bcaei o uxtz
I would like to write dynamic programming approach in which I will be able to count how many possibilities I can have.
Any help will be appreciated, thank you
No need for dynamic programming. Once you've located the vowels, the first is necessary in the first word, the last in the third. So you just have to enumerate the factors in between, aeiou -> eio, so in the middle you can have e, ei, eio, i, io, o. Two loops are sufficient.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to print a range of integers (all the positive integers that to be found between the user's 2 input integers) and I need to do it by the order the user typed it.
for example:
for the input: 4,9 output would be: 4 5 6 7 8 9
and for the input: 9,4 the output would be: 9 8 7 6 5 4
I'm not allowed to use any array/strings/functions, just basic C commands.
Anybody have any ideas?
Since this is most likely a learning exercise, here are some points to think about:
You need a loop.
The loop starts at the first number the user enters, and ends upon reaching the second number
The step of the loop depends on the order of the numbers entered by the user
If the first number is smaller than the second one, the step of the loop is one
If the first number is larger than the second one, the step of the loop is negative one
Therefore, the structure of your program is going to be as follows:
Prompt the user for the two numbers
Read numbers one and two
Compute the step using an if
Print out the range using a loop (for, while, or do/while, it's up to you).
This should be enough to complete your assignment. Good luck!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to make a C program to arrange a jumble word into meaningful English word.There is a file "dictionary.txt" which contains lots of jumbled words. So, i have to write a program which read the jumble word from this file and convert it into a meaningful word.
For example:-
dictionary.txt file exits a "epemaxl" word
when we provide this input, the output should come "example".
I have searched alot over internet but didnot get a suitable example according to this.
Please help me.
Thanks in advance.
One strategy can be to calculate the levenshtein distance and select the word that has the closest levenshtein distance to your jumble word.
If you are on Linux (say Debian or Ubuntu, can't tell about the rest of flavors), you could skip the making of real dictionary and just check with /usr/share/dict/ wordlist.