子串是,在字符位置 pos 开始,跨越 len 个字符(或直到字符串的结尾,以先到者为准)对象的部分。
1 2 3
string str="We think in generalities, but we live in details."; string str2 = str.substr (3,5); // "think" string str3 = str.substr (3); // get from "think" to the end
// inserting into a string #include<iostream> #include<string>
intmain() { std::string str="to be question"; std::string str2="the "; std::string str3="or not to be"; std::string::iterator it;
// used in the same order as described above: str.insert(6,str2); // to be (the )question str.insert(6,str3,3,4); // to be (not )the question str.insert(10,"that is cool",8); // to be not (that is )the question str.insert(10,"to be "); // to be not (to be )that is the question str.insert(15,1,':'); // to be not to be(:) that is the question it = str.insert(str.begin()+5,','); // to be(,) not to be: that is the question str.insert (str.end(),3,'.'); // to be, not to be: that is the question(...) str.insert (it+2,str3.begin(),str3.begin()+3); // (or )
/* Author: Yuki GitHub: https://github.com/Yuki-14544869/ Blog: https://yuki-14544869.github.io/ */ #include <bits/stdc++.h> #define LL long long using namespace std; const int INF = 0x3f3f3f3f; LL HilbertNumber(int n, int x, int y) { if(n==0) return 1; int m = 1<<(n-1);
if(x<=m) { if(y<=m) return HilbertNumber(n-1, y, x); else return 1LL*m*m + HilbertNumber(n-1, x, y-m); } else { if(y>m) return 2LL*m*m + HilbertNumber(n-1, x-m, y-m); else return 3LL*m*m + HilbertNumber(n-1, m+1-y, 2*m+1-x); } } int main() { int n, x, y; cin >> n >> x >> y; cout << HilbertNumber(n, x, y) << endl; return 0; }
public class Main { /* Author: Yuki GitHub: https://github.com/Yuki-14544869/ Blog: https://yuki-14544869.github.io/ */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int y = in.nextInt();
System.out.println(HilbertNumber(n, x, y)); in.close(); } public static long HilbertNumber(int n, int x, int y) { if(n==0) return 1; int m = 1<<(n-1);