也不知道是什么问题我下午会居然觉得这道题好难。
明明一个flag可以解决的事情嘛……
顺便陈越姥姥萌死了<(=Д=)/~
#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
vector<string> get(string s)
{
vector<string>v;
string t;
int flag = 0;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '[')
{
flag = 1;
}
else if (s[i] == ']')
{
v.push_back(t);
flag = 0;
t.clear();
}
else if(flag)
{
t += s[i];
}
}
return v;
}
int main()
{
string s[3];
for (int i = 0; i < 3; i++)
{
getline(cin,s[i]);
}
vector<string>hand = get(s[0]);
vector<string>eye = get(s[1]);
vector<string>month = get(s[2]);
int n;
cin >> n;
while (n--)
{
int h1, e1, m, e2, h2;
cin >> h1 >> e1 >> m >> e2 >> h2;
if (h1 <= 0 || h1 > hand.size() || h2 <= 0 || h2 > hand.size() || e1 <= 0 || e1 > eye.size() || e2 <= 0 || e2 > eye.size() || m <= 0 || m > month.size())
printf("Are you kidding me? @\\/@\n");
else
cout<<hand[h1-1]<<"("<<eye[e1-1]<<month[m-1]<<eye[e2-1]<<")"<<hand[h2-1]<<endl;
}
system("pause");
}
函数get的思想就是把[]中的内容提取出来放如vector,然后vector就可以直接用size函数得知数量,以及可以用下标调用。
最后就只有判断序号是否存在了。其实我们也可以先在vector中随便放点什么然后直接用,这样就可以不用每次都去-1了。
还有一点就是小心错误标号输出的时候的那个‘\’ 我们输出需要\\