Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
void all_characters_are_the_same(const std::string& str) {
|
||||
void all_characters_are_the_same(std::string_view str) {
|
||||
size_t len = str.length();
|
||||
std::cout << "input: \"" << str << "\", length: " << len << '\n';
|
||||
if (len > 0) {
|
||||
|
|
@ -9,10 +9,10 @@ void all_characters_are_the_same(const std::string& str) {
|
|||
for (size_t i = 1; i < len; ++i) {
|
||||
if (str[i] != ch) {
|
||||
std::cout << "Not all characters are the same.\n";
|
||||
std::cout << "Character '" << str[i]
|
||||
<< "' (hex " << std::hex << static_cast<unsigned int>(str[i])
|
||||
<< ") at position " << std::dec << i + 1
|
||||
<< " is not the same as '" << ch << "'.\n\n";
|
||||
std::cout << "Character '" << str[i] << "' (hex " << std::hex
|
||||
<< static_cast<unsigned int>(str[i])
|
||||
<< ") at position " << std::dec << i + 1
|
||||
<< " is not the same as '" << ch << "'.\n\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
comment
|
||||
Return 0 if all the characters in s are the same
|
||||
(including the special case of an empty string),
|
||||
otherwise the first position where a character
|
||||
differs from the preceeding one(s)
|
||||
end
|
||||
function samechars(s = string) = integer
|
||||
var i, slen, result = integer
|
||||
slen = len(s)
|
||||
i = 1
|
||||
while i < slen and mid(s,i,1) = mid(s,i+1,1) do
|
||||
i = i+1
|
||||
if i = slen or slen = 0 then
|
||||
result = 0
|
||||
else
|
||||
result = i+1
|
||||
end = result
|
||||
|
||||
procedure report(str = string)
|
||||
var p = integer
|
||||
print "Test string "; chr(34); str; chr(34); \
|
||||
" has length ="; len(str)
|
||||
p = samechars(str)
|
||||
if p = 0 then
|
||||
print "The characters are all the same"
|
||||
else
|
||||
print "Characters differ starting at position";p;" ('"; \
|
||||
mid(str,p,1);"'=";right$(hex$(asc(mid(str,p,1))),2);"h)"
|
||||
print
|
||||
end
|
||||
|
||||
rem - apply to the test cases
|
||||
|
||||
report ""
|
||||
report " "
|
||||
report "2"
|
||||
report "333"
|
||||
report ".55"
|
||||
report "tttTTT"
|
||||
report "4444 444k"
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue