Skip to main content
Use ranges to shorten; add demo program
Source Link
Toby Speight
  • 7k
  • 1
  • 31
  • 43

C++ (gcc), 125 124 123123 115 bytes

  

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::ranges::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> int f(std::string s){return std::is_sorted(s.begin(),s.end())|std::is_sorted(s.rbegin(),s.rend());} 
#include<bits/stdc++.h> int f(auto s){using namespace std::ranges;return is_sorted(s)|is_sorted(s|views::reverse);} 

Demo program:

#include <cstdio> #include <string> int main(int argc, char **argv) { for (int i = 1; i < argc; ++i) std::printf(" %s -> %d\n", argv[i], f(std::string{argv[i]})); } 

C++ (gcc), 125 124 123 bytes

 

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> int f(std::string s){return std::is_sorted(s.begin(),s.end())|std::is_sorted(s.rbegin(),s.rend());} 

C++ (gcc), 125 124 123 115 bytes

 

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::ranges::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> int f(auto s){using namespace std::ranges;return is_sorted(s)|is_sorted(s|views::reverse);} 

Demo program:

#include <cstdio> #include <string> int main(int argc, char **argv) { for (int i = 1; i < argc; ++i) std::printf(" %s -> %d\n", argv[i], f(std::string{argv[i]})); } 
Commonmark migration
Source Link

#C++ (gcc), 125 124 123 bytes

C++ (gcc), 125 124 123 bytes

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> int f(std::string s){return std::is_sorted(s.begin(),s.end())|std::is_sorted(s.rbegin(),s.rend());} 

#C++ (gcc), 125 124 123 bytes

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> int f(std::string s){return std::is_sorted(s.begin(),s.end())|std::is_sorted(s.rbegin(),s.rend());} 

C++ (gcc), 125 124 123 bytes

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> int f(std::string s){return std::is_sorted(s.begin(),s.end())|std::is_sorted(s.rbegin(),s.rend());} 
It's a byte shorter without 'using namespace'
Source Link
Toby Speight
  • 7k
  • 1
  • 31
  • 43

#C++ (gcc), 125 124124 123 bytes

Very boring obvious solution. We use GCC's internal header to save many includes, and using namespace to shorten identifiers. Conveniently, std::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> using namespace std;intint f(std::string s){return std::is_sorted(s.begin(s),s.end(s))|is_sorted|std::is_sorted(s.rbegin(s),s.rend(s));} 

#C++ (gcc), 125 124 bytes

Very boring obvious solution. We use GCC's internal header to save many includes, and using namespace to shorten identifiers. Conveniently, std::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> using namespace std;int f(string s){return is_sorted(begin(s),end(s))|is_sorted(rbegin(s),rend(s));} 

#C++ (gcc), 125 124 123 bytes

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h> int f(std::string s){return std::is_sorted(s.begin(),s.end())|std::is_sorted(s.rbegin(),s.rend());} 
Changed operator to save 1 byte
Source Link
Toby Speight
  • 7k
  • 1
  • 31
  • 43
Loading
Source Link
Toby Speight
  • 7k
  • 1
  • 31
  • 43
Loading