2019新生赛 %%%xxh

笔记.md                                                                                                                                                   9/16/2019

%%%xxh

题目背景

小A是一名新入ACM协会的萌新,众所周知acm的训练日常就是水群膜大佬于是小A也加入了%群巨的行列中

输入格式

每行(不超过100行)包含一个被':'分隔开的字符串S(|S|<=100,)代表了一个人的QQid和他所说的话

输出格式

对于每个人说的话,如果他和前面某个人说过的话相同,则输出"%%%" + 最后一个说过这句话的人的QQid,如果他说"+1",输入前面一个人说的话,否则输出他本来说的话. 输入样例1

xxh:hehe ac:%%%xxh wa:xxhorz A:xxhtql

输出样例

hehe

%%%xxh

xxhorz xxhtql

输入样例2

xxh:abcdefg ac:abcdefg wa:+1 tle:wqe re:abcdefg

输出样例2

abcdefg %%%xxh abcdefg wqe

%%%ac

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 110;
struct node {
    string name;
    string meg;
};
node a[N];
string s;
int main(int argc, char *argv[]) {
    int idx = 0,pos,sign;
    while(cin >> s) {
        sign = 0;
        pos = s.find(':');
        a[idx].name = s.substr(0,pos);//截取 
        a[idx].meg  = s.substr(pos+1,s.size()-pos-1);
        if(a[idx].meg == "+1") {
            cout << a[idx-1].meg << endl;
            sign = 1;
        }
        for(int i=idx-1; i>=0; --i) {
            if(a[i].meg == a[idx].meg) {
                cout << "%%%" << a[i].name << endl;
                sign = 1;
                break;
            }
        }
        if(!sign)   cout << a[idx].meg << endl;
        idx++;
    }
    return 0;
}

 

 

 

 

 

 

猜你喜欢

转载自www.cnblogs.com/QingyuYYYYY/p/11817096.html
今日推荐