【PAT乙级】1052 卖个萌

题目链接:1052 卖个萌

思路

  1. getline输入三行,另写一个函数用于添加串内符号,判断至第n'['出现,将后续内容加入输出,直到']'结束加入。
  2. 注意错误输出中的'\'为转义符,无法单独输出,需改为"\\"

代码

#include <iostream>
#include <math.h>
using namespace std;

//输入选串及序号,将对应字符加入输出,成功返回1,失败返回0
int Select(string &out,string s,int no){
    int count = 0;
    for(int i=0;i<s.length();i++){
        if(s[i] == '[')count++;
        if(count == no){
            while(s[++i]!=']') out += s[i];
            return 1;
        }
    }
    return 0;
}

int main(){
    string hand,eye,mouth;
    getline(cin,hand);
    getline(cin,eye);
    getline(cin,mouth);
    int N,no,flag=1;
    cin >> N;
    string out[N];
    for(int i=0;i<N;i++){
        for(int j=0;j<5;j++){
            cin >> no;
            if(j==0||j==4) flag = Select(out[i], hand, no);
            if(j==1) out[i]+='(';
            if(j==1||j==3) flag = Select(out[i], eye, no);
            if(j==3) out[i]+=')';
            if(j==2) flag = Select(out[i], mouth, no);
            if (!flag){
                out[i]="Are you kidding me? @\\/@";
                break;
            }
        }
        cout << out[i] << endl;
    }
    
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值