int n = 0; int ans = 0; cin>>n; for(int _ = 1; _ <= n; ++ _) { int i = _; int flag = 1; int last = i % 10; while(1){ i /= 10; if(i == 0) { break; } if(last >= i % 10) { last = i % 10; }else{ flag = 0; break; } } ans += flag; } cout<<ans<<endl;
但是, 在有大量\的情况下我们不希望字符串中的 \ 字符被转义, 如在表示地址或正则表达式的时候. 因此, 很多语言提供了 Raw String 字面量, 在 Raw string 字面量中 \ 字符被视为普通的字符而不是转义符. 正如 Python 文档中描述的:
Both string and bytes literals may optionally be prefixed with a letter ‘r’ or ‘R’; such strings are called raw strings and treat backslashes as literal characters.
字符串与字节字面量都可以以一个 r 或者 R 前缀来表示原始字符串. 在原始字符串中, \ 字符被当做普通字符而不是转义符来处理.
Even in a raw literal, quotes can be escaped with a backslash, but the backslash remains in the result; for example, r""" is a valid string literal consisting of two characters: a backslash and a double quote; r"" is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw literal cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the literal, not as a line continuation.