Game to determine odd, even and prime numbers within text strings c# - c#

Here are the steps of the problem with examples in relation to the first part of the problem:
1 - The program asks the user to enter the number of questions to be asked.
2 - For each question, the program asks the user to enter a valid value between 3 and 100 that helps determine the number of symbols
generative
Randomly and the duty is to enumerate a number of numbers (odd, even or prime) according to the text of the question within this series
of icons. This value is an indicator of how difficult the question is.3- Each question is synthesized by merging several randomly generated codes. Symbols include uppercase letters
and small and numbers from 0 to 9. And then ask the user to specify a number for numbers (odd, even or prime) within
randomly.
this series. Determining the type of numbers to be counted (odd, even or prime) is also done
4 - For each question asked, the string generated is stored in an array and the question pattern is in a second array (pattern is
A question about odd numbers, a question about even numbers, or a question about prime numbers), the result is calculated and stored
correct results in a custom array in order to store the correct results, then the question is asked to the user and stored
The answer is in a custom matrix of user answers.For each question asked, the generated string is stored in an array and question pattern
For each question that is asked to the user, the answer is evaluated, and the evaluation result corresponding to each question is stored in
Matrix for evaluation of results. If the evaluation result is correct, the value 1 is stored, otherwise the value 0.
For any question the user can ignore the question but it is recorded as wrong answer.
The word to ignore the question is Ignore, and here the treatment should be (insensitive case.)
Prime numbers are integers greater than one and are only divisible by themselves.Regarding the second part of the question:
After the user is asked questions and answers are stored, the user can choose as many functions as possible
It performs statistical operations on the results stored within the arrays. Like the number of correct answers, the number of wrong answers.
These options are displayed repeatedly until the user types exit and the program ends.
The word to terminate the program is exit and here the treatment should be (insensitive case.)
The options are:
Display the number of wrong answers.
Display the number of correct answers.
Display the questions, the user's answers to them, and the correct answers corresponding to each question.
Option exit to end displaying options and exit the program

Related

How do I take an indefinitely large set of user inputs and save them into an array? [closed]

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 5 years ago.
Improve this question
I am making a program (in school for intro to computer programming(dont worry, this is all extra credit stuff, not asking for cheat answers)) that will take a user decided set of user inputs and save them all to do math (more specifically, finding the median, but I want to figure that out myself) on them. I am fairly sure that I need an array to do this (even my teacher hinted that that is what you needed to do).
My plan is to have a variable x that will decide the amount of separate numbers in the array (will not only be the number in the array, but also the number to check how many times I want to run the loop for asking for numbers), and then to have that many user inputted numbers inputting by the user, and then to be able to take those numbers and find the median of them (I will probably have to check if the number is even or odd first, then sort the numbers (somehow), then find the middlemost number.)
Thanks!
Instead of using array which has fixed size, try using List.
List allows you to add indefinitely many (until it fits into memory) elements.
So, in your for loop you could read user input and add it to the list.
After that you can sort entire list using sort method and return middle element, which is a median.
It could look like that:
int n = //TODO: read number of user inputs
List<int> elems = new List<int> ();
for (int i = 0; i < n; i++) {
int x = // get input
elems.Add(x);
}
Console.WriteLine(elems[elems.Length / 2]);
You can take a look at the List<T> class here for storing the numbers.
For reading input, see Console.ReadLine.
For converting string to int, take a look at int.TryParse.
I gave you the tools, now start coding! :D

C# Check if a string is a Sentence [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Basically I want to check if a String is a Sentence ("Hello, I am Me!") or Symbol Spam ("HH,,,{''{"), without using the number of symbols as a factor as much as possible. Right now it just detects based on a counter of symbols, but when someone says something with lots of punctuation, they get kicked.
Help?
If the number of symbols in the text is not sufficient, and you don't want to use something too fancy (or bought) could I suggest implementing one or more of these further steps (of increasing difficulty):
Make a count of all A-Za-z and space characters in the string and make a ratio of this to the count of symbols - so if they write a sentence then !!!!!!!!!!!!! at the end it still doesn't snag as the ratio is high enough.
If this still isn't discerning enough, add a further check if you pass item 1...
Count numbers of consecutive A-Za-z characters in the string - work out the average length of these 'words' - if the average is too short then it is probably spam.
These can be done in RegEx reasonably easily - If you want more sophistication then you have to use something written by someone else that has much more developed statistical methods (or start reading lexographical university papers that are beyond me!)

Porter stemmer algorithm in information-retrieval [closed]

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 7 years ago.
Improve this question
I need to create simple search engine for my application. Let's simplify it to the following: we have some texts (a lot) and i need to search and show relevant results.
I've based on this great article extend some things and it works pretty well for me.
But i have problem with stemming words to terms. For example words "annotation", "annotations" etc. will be stemmed to "annot", but imagine you try search something, and you will see unexpected results:
"anno" - nothing
"annota" - nothing
etc.
Only word "annot" will give relevant result. So, how should i improve my search to give expected results? Because "annot" contains "anno" and "annota" is slightly more than "annot". Using contains all the time obviously isn't the solution
If in first case i can use some Ternary search tree, in second case i don't know what to do.
Any ideas would be very helpful.
UPDATE
oleksii has pointed me to n-grams here, which may works for me, but i don't know how to properly index n-grams.
So the Question:
Which data structure would be the best for my needs
How properly index my n-grams
Stemming perhaps isn't much relevant here. Stemming will convert a plural to a singular form.
Given you have a tokeniser, a stemmer and a cleaner (to remove stop words, perhaps punctuation and numbers, short words etc) what you are looking at is a full-text search. I would advice you to get an off-the-shelf solution (like Elasticsearch, Lucene, Solr), but if you fancy a DIY approach I can suggest the following naive implementation.
Step 1
Create a search-orientated tokeniser. One example would be an n-gram tokeniser. It will take your word and split into the following sequences:
annotation
1 - [a, n, o, t, a, i]
2 - [an, nn, no, ot, ...]
3 - [ann, nno, not, ota, ...]
4 - [anno, nnot, nota, otat, ...]
....
Step 2
Sort n-grams for more efficient look-up
Step 3
Search n-grams for exact match using binary search

How to do password validation with regex? [closed]

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
Conditions :
Passwords must have at least 8 characters, which combine the use of at least 2 of the following: upper and lower case letters, numbers, and special characters.
Which pattern can fit with conditions?
Regular expressions are the completely wrong approach for this. Instead simply count the number of occurrences of each character type and then simply use if statements and boolean logic to check if your requirements are met.
However, reconsider if what you want to do is a good idea:
Restricting the symbols is a horribly bad idea. Any character should be allowed
When the password has a certain length, requiring e.g. symbols/numbers/mixed-case loses lots of its purpose. Additionally an attacker cannot know if some user uses just lowercase chars or just digits in his password and thus he cannot tune a brute-force attack to use only those chars - and since you'll hopefully be throttling incorrect logins brute-force is not a good option anyway.
Imagine "correct horse battery staple" from the famous xkcd. While all those words are in a dictionary and might even fail a improperly implemented password check, it's very secure. While a single dictionary word is extremely insecure multiple of them will be easy to remember and secure (an attacker would have to try all e.g. 4-word combinations which are A DAMN LOT even with just a 1000 word dictionary).
So a much better password policy would:
Reject obviously bad sequences. That's consecutive digits like 12345 or 54321. qwertz, qwerty, etc. are also bad.
Reject any password that can be found in a dictionary as a whole. Make sure to use both an english dictionary and one for each language your site supports.
Reject any other password that is likely to be insecure. Contains the username (even if backwards)? Nope. Contains the part before the # of the user's email address? Nope. Contains his birthdate? Nope.
Require at least 8 characters (as you already intend to do).
There's also an interesting post on the IT Security Stack Exchange site which you should read: Short complex password, or long dictionary passphrase?
string PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[##$%]).{8,20})";
string password = "Password#1#";
Regex.IsMatch(password,PASSWORD_PATTERN);
try this.

C# Calculator Text Input Validation [closed]

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 am currently writing a calculator application. One part of this application is a Simple Calculator that works like the calculator in windows (using windows 8). It can parse the numbers entered in the textbox. However, if the user does not enter in the correct form such as 5 * * 5 it will give an error. I want it to check the character entered before to see if its an operator and if it is, replace it such as 5 * / 5 to become 5 / 5 as the user is typing. Also it will need to check the parenthesis are in the correct order such as () or () not )(. The other thing it will need to check is that the number being entered only has one decimal point. For example, 4.38585 + 5.32948. I have already limited key entries to only numbers and operators. I have checked this for some time now, but have not seen any solutions.
If you're going to allow the user to enter an expression and then make him press a "calculate" button, then you should not validate things on the fly. Let the user make mistakes, since he will anyway. The user will want to go back and edit the text that he's entered. Your editing rules will make that difficult or impossible. Or worse, inconsistent.
For example, say that the user enters 4.35*7.29.
Then he realizes that he wanted to divide. But your editing rules won't let him delete the * because that would make for an invalid number. And he can't enter the / first and then delete, because doing so would give /* or */, both of which are invalid. Are you going to allow the temporary invalid expression when editing, but not allow it when the user is typing? That would be inconsistent, and wouldn't prevent your evaluator from having to do the error checking again and notify the user.
Limit keystrokes to numbers and operators if you like, but don't try to validate the form of what the user inputs. Let him type **)9(// if he wants. Handle the error when you're parsing--AFTER the user has pressed the calculate button.
Now, if your application works like Windows Calculator in that it keeps a running total as the user enters values and operators, that's a different matter. But what you're talking about would just be frustrating. I certainly wouldn't want to use it.

Categories