截取字符串(C++牛客网)

解题思路:

(1)substr

#include<iostream>

using namespace std;

int main() {
    int n;
    string s;
    while(cin>>s) {
        cin>>n;
        cout<<s.substr(0,n)<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/coolsunxu/article/details/115064335