Count char occurs in string with length 10^200 [closed] - c++

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 8 years ago.
Improve this question
I have a string on Linux standard terminal input. Its maximal length is 10^200 (as said in program specification). I have to count, how many "3" characters are inside it (occur in this string). I couldn't do that by for loop, because there is no so big variable type, which can be used as iterator. Is there any way to analyze so big strings?

Is there any way to analyze so big strings?
Not in this universe there is not. Such an entity cannot exist in this universe1 and that which does not exist, cannot be analyzed.
1 Current estimates of this universe's total number of particles particles are in the region of 1080.

As from your comment
The data source is standard terminal input.
Then you'll need a lot of monkeys to type this in.
Though you don't need to read in what's typed at once into a big string, but you can simply analyze char by char as typed. The std::istream::get(char_type& ch) method is suitable for doing so.

Related

Special chars displaying properly on every computer [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
Can this code assure that Polish special chars will be properly displayed on every computer?
locale locpol("Polish_Poland");
locale::global(locpol);
cout.imbue(locpol);
cin.imbue(locpol);
On mine it works, cannot say about any other PC as I'm limited to only one.
Second thought: how can I preserve special chars during i/o operations and comparison. I've been told Windows has different char-codes for receiving and displaying chars. Is this true? How can I properly compare strings with special characters?
Do I need to imbue locale on... let's say - every ofstream/ifstream object I create? Like this:
textfile.imbue(locpol);
?
No.
The names of the locales are not standardized, so there are no guarantees across operating systems.

Declaring certain elements as const in an array c++, sudoku solver [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 8 years ago.
Improve this question
Is it possible for me to take an existing array and make certain values (not all) constant? I'm trying to build a sudoku solver and my idea is to have the user enter values, so I would like to have those values remain constant as I change the empty spaces. Any tips or advice with the solver would also be appreciated. This is my first quarter working with c++. Thanks!
No. Const is essentially a compile-time idea. It's not something that can be toggled as a program is running.
If you need certain values to remain untouched while others are changed, then you need to put that into your data and logic. For instance, each value might have an associated boolean that indicates whether or not it can be changed. Then write your logic to respect that boolean.

C++ take a user input as the number of dimensions an array has? [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 8 years ago.
Improve this question
I can't seem to find anything regarding whether or not this is possible. Ideally I'd have someone input an integer like "4" and then it would make a 4-d array.
is this at all possible?
As explained in the Stack Overflow post, "Create an N dimensional array, where N is determined at runtime (C++)":
The dimensions of an array are part of the type, and the type must be known
at compile time.
Thus the programmer must specify the dimensions of the array before compile-time, not during run-time.
Type checking is typically one of the first operations a compiler does (it is specifically found in the semantic analysis portion of the compiler's control flow) to ensure the code received is free of simple programming errors (assignment/equivilance errors, etc).
Please let me know if you have any questions!

what does this stanford lirbrary mean? C++ simpio.h getInteger() [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 8 years ago.
Improve this question
i'm trying to understand this library that stanford uses for their CS course but i can't just use this feature in my CS course back in my home. How do i emulate this feature? i was wondering is this a getline(cin, integer)? or is this something to do with fstream? The reason being, i'm trying to go through the lecture series at UDEMY.
Here is the definition.
int getInteger(string prompt = "");
Reads a complete line from cin and scans it as an integer. If the scan
succeeds, the integer value is returned. If the argument is not a
legal integer or if extraneous characters (other than whitespace)
appear in the string, the user is given a chance to reenter the value.
If supplied, the optional prompt string is printed before reading the
value.
Usage:
int n = getInteger(prompt);
You can download simpio.h here: http://www.eecs.wsu.edu/~cs150/prog/libs.htm
If you can't or don't want to use the library, you could study its source code.

In C++ what's the easiest way for a user to enter data going into a 2D array? [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 8 years ago.
Improve this question
I want the program to take user input to fill a 2D array of ints and I'm not sure what the easiest format to have the user enter the data would be (easy in terms of programming).
For example in Java I could use .split() to separate integers by spaces or commas etc., but since a string can't easily be broken up in C++, this is a problem.
I don't want to prompt the user each time for each element such as:
enter integer for location 0, 0
enter integer for location 0,10
enter integer for location 2, 0
Here is a stackoverflow answer that talks about how to tokenize a string in C++
How do I tokenize a string in C++?
I haven't tried boost but strtok is pretty easy to use but may have some multithreading issues.