PAT 1052 卖个萌

也不知道是什么问题我下午会居然觉得这道题好难。

明明一个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了。

还有一点就是小心错误标号输出的时候的那个‘\’ 我们输出需要\\

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值