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
What i have is an array containing strings of length = 31. Total number of strings = 13700. I want to split all strings into substrings of length 5,22 and 4. Please help. Thank you.
With fixed-length strings and fixed-length substrings it's really easy. If they're not already, mash the strings around until they're in a 2-D char array, one string per row (cell2mat() will be your friend if they're currently in a cell array), and split:
s1 = s(:, 1:5);
s2 = s(:, 6:27);
s3 = s(:, 28:31);
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
string = "this is an example string"
in haskell, how can i count how many times the character 'a' appears in the string above? Preferably in one line.
Think about it this way: you want to know the size of the list in which all letters that are not 'a' have been removed. To remove these, we can use filter. This function filters out any items in a list that do not satisfy a given predicate. Then getting the size of this list is trivial with length.
length $ filter (\x -> x=='a') "this is an example string"
Edit:
As per AndrewC's suggestion, you can also write this as:
length $ filter (=='a') "this is an example string"
This way is more readable and clearer.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I have a sheet with some datas in D column. I need to extract the values that have less then 11 characters and adding from left many 0 untill reach 11 characters.. I explain with an example:
12345678912 --> this is correct
123456789 --> this is incorrect and has 9 characters so i need adding from left 2 zeros
result:
00123456789 --> now is correct
Is there a macro or a formula that could be useful for my goal? Thanks
Assuming the data is stored as numbers, you can simply use =TEXT(A1,"00000000000"). If it's stored as text then use =REPT("0",LEN(A1)-11))&A1
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 need to solve the following problem:
Give a linear-time algorithm to determine if a text T is a cyclic rotation of another string T'. For example, arc and car are cyclic rotations of each other.
I have no idea where to start. How can I solve this problem?
As a hint: if x and y have the same length, then x is a cyclic rotation of y iff x is a substring of yy. Try proving this and using this as the basis for your algorithm.
Hope this helps!
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
Given a set of 10 symbols and a set of strings(at max 100) of length at max 20 each consisting of these symbols, find the maximum length string which can be made from these symbols that doesn't have any of the given strings as its sub-string. In case, if we can have infinite long string satisfying the property, print -1.
Besides brute force algorithm which will go exponential in time, I am not able to get any solution for this.
Any hint to approach this problem will be thankful.
Given a set of strings that need to be matched, my immediate reaction is to use http://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm to create a matcher. This matcher is a finite state machine that accepts one character at a time and tells you which state you end up in next, given that character.
So I think you can reduce the problem to accepting a directed graph and a starting point and finding the longest route through that graph that does not go through the nodes that correspond to pattern matches - which I think we can simply delete from the graph. This is covered in http://en.wikipedia.org/wiki/Longest_path. Constructing this graph is also linear so the whole thing seems to be O(n)
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
How do I find if a string contains a contiguous palindromic sequence ? I could try the naive solution in O(n^2) time where n is the string size , but any efficient algos to it ?
Well looking for just any palindrome isn't particularly interesting since every one character string is a palindrome. If you are looking for the longest palindrome you may be interested in Manacher's Algorithm.
A good description of the algorithm can be found here.
This is a quite common problem, and has ample results on google:
http://en.wikipedia.org/wiki/Longest_palindromic_substring
Rather than using Manacher's Algorithm you should use one of the parallel algorithms.
duplicate of : how to find longest palindromic subsequence?