题目链接:http://ac.jobdu.com/problem.php?pid=1029

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

 

//
//  1029 魔咒词典.cpp
//  Jobdu
//
//  Created by PengFei_Zheng on 30/04/2017.
//  Copyright © 2017 PengFei_Zheng. All rights reserved.
//
 
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#define MAX_SIZE 110
//#define debug
using namespace std;
 
map<string,string> myMap;
 
char s[MAX_SIZE];
string str;
string curse;
string fun;
int n;
 
int main(){
#ifdef debug
    freopen("/Users/pengfei_zheng/Desktop/input.txt", "r", stdin);
#endif
    while(gets(s)){
        str = s;
        if(str=="@END@") break;
        int len = (int)str.size();
        int i;
        for(i = 0 ; i < len ; i ++){
            if(str[i]==']')
                break;
        }
        curse = str.substr(0,i+1);
        fun = str.substr(i+2,len);
        myMap[curse]=fun;
        myMap[fun]=curse;
    }
    scanf("%d\n",&n);
    while(n--){
        gets(s);
        str = s;
        if(myMap.count(s)==0){
            printf("what?\n");
        }
        else{
            string tmp = myMap[str];
            if(tmp[0]=='['){
                tmp = tmp.substr(1,tmp.length()-2);
            }
            printf("%s\n",tmp.c_str());
        }
    }
    return 0;
}
/**************************************************************
    Problem: 1029
    User: zpfbuaa
    Language: C++
    Result: Accepted
    Time:20 ms
    Memory:2716 kb
****************************************************************/
参考代码

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-12-12
  • 2021-09-02
  • 2021-12-21
猜你喜欢
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案