E
This's the problem. std::isupper and std::islower several overloads, some declared <cctype>Others <locale>♪ Apparently default in vc++ and standard gcc library, these headline files are differently included in other headline files. If vc++ is clearly inclined <locale>I don't know what to do.In such cases, there should be a clear indication that the indicator should be preceded by a necessary overload:#include <algorithm>
#include <cctype>
#include <string>
void solve(::std::string & str)
{
using t_Predicate = int ( * )(int);
constexpr auto const p_up{static_cast<t_Predicate>(::std::isupper)};
constexpr auto const p_low{static_cast<t_Predicate>(::std::islower)};
auto const up_num{::std::count_if(str.begin(), str.end(), p_up)};
auto const low_num{::std::count_if(str.begin(), str.end(), p_low)};
if (low_num < up_num)
{
::std::for_each(str.begin(), str.end(), p_up);
}
else
{
::std::for_each(str.begin(), str.end(), p_low);
}
return;
}
https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:%271%27,fontScale:14,fontUsePx:%270%27,j:1,lang:c%2B%2B,selection:(endColumn:52,endLineNumber:9,positionColumn:52,positionLineNumber:9,selectionStartColumn:52,selectionStartLineNumber:9,startColumn:52,startLineNumber:9),source:%27%23include+%3Calgorithm%3E%0A%23include+%3Ccctype%3E%0A%23include+%3Cstring%3E%0A%0Avoid+solve(::std::string+%26+str)%0A%7B%0A%09using+t_Predicate+%3D+int+(+*+)+(int)%3B%0A%09constexpr+auto+const+p_up%7Bstatic_cast%3Ct_Predicate%3E(::std::isupper)%7D%3B%0A%09constexpr+auto+const+p_low%7Bstatic_cast%3Ct_Predicate%3E(::std::islower)%7D%3B%0A%09auto+const+up_num%7B::std::count_if(str.begin(),+str.end(),+p_up)%7D%3B%0A%09auto+const+low_num%7B::std::count_if(str.begin(),+str.end(),+p_low)%7D%3B%0A%09if+(low_num+%3C+up_num)%0A%09%7B%0A%09%09::std::for_each(str.begin(),+str.end(),+p_up)%3B%0A%09%7D%0A%09else%0A%09%7B%0A%09%09::std::for_each(str.begin(),+str.end(),+p_low)%3B%0A%09%7D%0A%09return%3B%0A%7D%0A%27),l:%275%27,n:%270%27,o:%27C%2B%2B+source+%231%27,t:%270%27)),k:54.412532637075714,l:%274%27,n:%270%27,o:%27%27,s:0,t:%270%27),(g:!((g:!((h:compiler,i:(compiler:g112,filters:(b:%270%27,binary:%271%27,commentOnly:%270%27,demangle:%270%27,directives:%270%27,execute:%271%27,intel:%270%27,libraryCode:%270%27,trim:%271%27),flagsViewOpen:%271%27,fontScale:14,fontUsePx:%270%27,j:1,lang:c%2B%2B,libs:!(),options:%27-std%3Dc%2B%2B17+-Wall+-Wextra+-Wconversion+-Wpedantic+-Werror%27,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1,tree:%271%27),l:%275%27,n:%270%27,o:%27x86-64+gcc+11.2+(C%2B%2B,+Editor+%231,+Compiler+%231)%27,t:%270%27)),k:50,l:%274%27,m:25.59456398640997,n:%270%27,o:%27%27,s:0,t:%270%27),(g:!((h:output,i:(compiler:1,editor:1,fontScale:14,fontUsePx:%270%27,tree:%271%27,wrap:%270%27),l:%275%27,n:%270%27,o:%27Output+of+x86-64+gcc+11.2+(Compiler+%231)%27,t:%270%27)),header:(),l:%274%27,m:74.40543601359003,n:%270%27,o:%27%27,s:0,t:%270%27)),k:45.587467362924286,l:%273%27,n:%270%27,o:%27%27,t:%270%27)),l:%272%27,n:%270%27,o:%27%27,t:%270%27)),version:4 Z.A. The cctype predictors don't even use at all because they can use the current elbow. Do one normal cycle first, counting the number of letters in the top / bottom register, and then the second normal cycle for the transformation of the register.