标签:using algorithm amp set ack 乙级 start pac ble
#include<string> #include<iostream> using namespace std; int main() { string s("12345asdf"); string a = s.substr(0,5); //获得字符串s中从第0位开始的长度为5的字符串 cout << a << endl; }
//输出结果为:12345
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <cmath> #include <algorithm> using namespace std; vector<string> v1,v2,v3; string str1,str2,str3; void init(vector<string> &v,string s) { int k=0,start; for(int i=0;i<s.length();i++) { if(s[i]==‘[‘) { start=i+1; k=0; } else if(s[i]==‘]‘) { v.push_back(s.substr(start,k)); } else k++; } } int main() { string s; s.clear(); getline(cin,s); init(v1,s); s.clear(); getline(cin,s); init(v2,s); s.clear(); getline(cin,s); init(v3,s); s.clear(); int arr[10]={0},k; int len1=v1.size(),len2=v2.size(),len3=v3.size(); bool flag=true; cin>>k; for(int i=0;i<k;i++) { for(int j=0;j<5;j++)
{ cin>>arr[j]; if(arr[j]<1) flag=false; } if(arr[0]>len1||arr[1]>len2||arr[2]>len3||arr[3]>len2||arr[4]>len1) flag=false; if(!flag) cout<<"Are you kidding me? @\\/@"<<endl; else cout<<v1[arr[0]-1]<<"("<<v2[arr[1]-1]<<v3[arr[2]-1]<<v2[arr[3]-1]<<")"<<v1[arr[4]-1]<<endl; } return 0; }
PTA乙级 (1052 卖个萌 (20分),(substr函数))
标签:using algorithm amp set ack 乙级 start pac ble
原文地址:https://www.cnblogs.com/jianqiao123/p/12229483.html