Problem 61. Find state names that end with the letter A
Given a list of US states, remove all the states that end with the letter A.
Example:
Input s1 = 'Alabama Montana Nebraska Vermont Nevada'; Output s2 is ' Vermont ';
Solution Stats
Problem Comments
-
10 Comments
I believe this problem has the wrong assertion for part 2. The space rule seems to be to keep spaces between words unless it is something like North Dakota in which you delete the space between the two words. Missouri New Hampshire seems to be missing a space, as only 3 are present. With three entries to delete there should be four spaces Missourix1x2x3xNew (4 x's or spaces for 3 matches).
There's an error in the second test case. This is what's returned: "Error: Error: A MATLAB string constant is not terminated properly." I assume this is due to there being an accidental new-line character in the input string.
I've cleaned up the second test. There was a bad character in there somewhere, but it's working now and I've rescored all the answers.
I get the infamous "Remove inappropriate content" message when trying to submit a solution to this problem.
This is a bizarre one - test case is dependent on how many spaces are between the state names, which points to a specific solution having to be used rather than a solution that makes sense to the user.
Additionally, I have noticed a stange effect in 19a when I use "join". My solution has too few spaces between "Delaware" and "Hawaii", so I thought I'd just bung another one in there with "join". If I do:
s2 = cell2mat(join(s2," ")), % I get the same number of spaces
s2 = cell2mat(join(s2," ")) % I get too many spaces!
Driving me wild...
@Kiran Ramsaroop, instructions are to remove state names, not spaces. It may seem silly to want this, but it is accurate.
Thus only spaces that are part of a removed state name should be removed.
tough
Be careful of the 2-word states.
Converting to different formats boggles me
I don't want to go through to effort to solve such a irrelevant problem!
I will cheat!
if (s1{id}(1) == 'W' & s1{id}(end) == 't') | s1{id}(end) == 'h'
% Do nothing...
bruh matlab stands for matrix laboratory, not states with the letter A remover lmao
Solution Comments
Show commentsProblem Recent Solvers1176
Suggested Problems
-
1304 Solvers
-
Create a cell array out of a struct
1831 Solvers
-
Back to basics 17 - white space
271 Solvers
-
Permute diagonal and antidiagonal
447 Solvers
-
Generate a random matrix A of (1,-1)
314 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!