首页 > 试题广场 >

魔咒词典

[编程题]魔咒词典
  • 热度指数:11902 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
    哈利波特在魔法学校的必修课之一就是学习魔咒。据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助。     给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒。如果他要的魔咒不在词典中,就输出“what?”

输入描述:
    首先列出词典中不超过100000条不同的魔咒词条,每条格式为:

    [魔咒] 对应功能

    其中“魔咒”和“对应功能”分别为长度不超过20和80的字符串,字符串中保证不包含字符“[”和“]”,且“]”和后面的字符串之间有且仅有一个空格。词典最后一行以“@END@”结束,这一行不属于词典中的词条。
    词典之后的一行包含正整数N(<=1000),随后是N个测试用例。每个测试用例占一行,或者给出“[魔咒]”,或者给出“对应功能”。


输出描述:
    每个测试用例的输出占一行,输出魔咒对应的功能,或者功能对应的魔咒。如果魔咒不在词典中,就输出“what?”
示例1

输入

[expelliarmus] the disarming charm
[rictusempra] send a jet of silver light to hit the enemy
[tarantallegra] control the movement of one's legs
[serpensortia] shoot a snake out of the end of one's wand
[lumos] light the wand
[obliviate] the memory charm
[expecto patronum] send a Patronus to the dementors
[accio] the summoning charm
@END@
4
[lumos]
the summoning charm
[arha]
take me to the sky

输出

light the wand
accio
what?
what?
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
int main(){
    int d,l;
    string s;
    map<string,string> mp;
    while(getline(cin,s)){
        if(s=="@END@") break;
        d=s.find("]");//定位指定字符的位置,为了将字符串分割
        l=s.length();
        string m=s.substr(0,d+1);//利用substr提取相关字符串
        string n=s.substr(d+2,l);
        mp[m]=n;//将分开的两段字符串分别映射成键和值
        mp[n]=m;
    }
    int n;
    scanf("%d",&n);
    getchar();
    string t;
    while(n--&&getline(cin,s)){
            if(mp[s]==""){//如果没有找到相关的映射
                cout<<"what?"<<endl;
            }else{
               t=mp[s];
               if(t.find("[")!=-1){//如果找到的字符串里含有指定字符,就利用substr去除
                    cout<<t.substr(1,(t.length()-2))<<endl;
                }else{//如果没有就直接输出
                    cout<<t<<endl;
                }
            }
    }
    return 0;
}

发表于 2019-03-05 20:17:39 回复(1)
纯C语言解法
#include <stdio.h> #include <string.h> char str[100005][120]; char dst[120]; char temp[120]; int main() {     int cnt=0;     while(fgets(str[cnt],200,stdin))     {         if(strcmp(str[cnt],"@END@\n")==0) break;         cnt++;     }     int i,j,k,n; //    while(scanf("%d",&n)!=EOF) //    {         scanf("%d",&n);         getchar();         for(i=0;i<n;i++)         {             fgets(dst,120,stdin);             int len=strlen(dst);             dst[len-1]='\0';             int flag=0;             for(j=0;j<cnt;j++)             {                 char* p=str[j];//指向魔咒词典的每一个条目                 int length=strlen(p);                 if(strchr(dst,'[')&&strchr(dst,']')&&strstr(p,dst))//输入魔咒名,查询魔咒功能                 {                     char* q=strchr(p,']');//找到']'出现的位置                     strncpy(temp,p,q-p+1);//将词典条目当中的魔咒名拷贝到字符数组temp当中                     temp[q-p+1]='\0';                     if(strcmp(temp,dst)==0)//确保待查询的魔咒名与词典中的魔咒名完全一致(防止子串)                     {                         flag=1;                         printf("%s",p+len);                         break;                     }                 }                 else//输入魔咒功能,查询魔咒名                 {                     if(strstr(p,dst))                     {                         char* q=strchr(p,']');                         strcpy(temp,q+2);                         temp[p+length-q-3]='\0';//将魔咒词典当中的魔咒功能拷贝到字符数组temp当中                         if(strcmp(temp,dst)==0)                         {                             flag=1;                             for(k=1;k<q-p;k++)                             {                                 printf("%c",p[k]);                             }                             printf("\n");                             break;                         }                     }                 }             }             if(flag==0) printf("what?\n");         } //    }     return 0; }
编辑于 2018-08-20 15:53:02 回复(4)
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std; 

// 字典中查找对应键的值没有的话返回what
string find(map<string, string> m, string s) {
    if(m.find(s) != m.end())
        return m[s];
    else 
        return "what?";
}

int main()
{
    int n;
    string name;
    map<string, string> m1;
    map<string, string> m2;
    while(true) {
        string name, function, t;
        char temp[80];
        gets(temp);
        t = temp;
        if(t == "@END@") break;
        int pos = t.find(']');
        name = t.substr(1, pos-1);    // 截取魔咒
        function = t.substr(pos+2, t.length()-name.length()-3);    // 截取功能
        m1[name] = function;
        m2[function] = name;
    }

    cin>>n;
    getchar();
    while(n--) {
        string t;
        char temp[80];
        gets(temp);
        t = temp;
        if(t[0] == '[') {
            cout<<find(m1, t.substr(1, t.length()-2))<<endl;
        } else {
            cout<<find(m2, t)<<endl;
        }
    }
    return 0;
}
发表于 2018-03-26 10:49:15 回复(0)

python solution:

思路,使用双字典,对于输入的每条数据,分成key和val,一个字典的key是key,另一个字典的key是val。这样查询起来效率更高一些。


accept 代码如下:

dkey, dvalue = dict(), dict()
a = input()
while a != "@END@":
    key, val = a.split("] ")
    dkey[key[1:]] = val
    dvalue[val] = key[1:]
    a = input()
for i in range(int(input())):
    a = input()
    if a.startswith("["):
        if a.strip("[").strip("]") in dkey.keys():
            print(dkey[a.strip("[").strip("]")])
        else:
            print("what?")
    else:
        if a in dvalue.keys():
            print(dvalue[a])
        else:
            print("what?")
编辑于 2017-10-25 15:12:03 回复(0)
try:
    while 1:
        a, b = {}, {}
        while 1:
            Item = raw_input()
            if Item == '@END@':
                break
            Index = Item.index(']')
            Word, Function = Item[:Index + 1], Item[Index + 2:]
            a[Word], b[Function] = Function, Word
       	for i in xrange(input()):
            Query = raw_input()
            if Query in a:
                print a[Query]
            elif Query in b:
                print b[Query][1: -1]
            else:
                print 'what?'
except:
    pass

发表于 2016-12-27 00:43:06 回复(0)
先说下坑:[魔咒]里会有空格,这就是为什么示例1过了但提交过不了的原因。
大家都用哈希,我试试二分,虽然代码有些啰嗦,但速度还是挺快的。
以下是纯C代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
    char name[23];
    char content[81];
} Enchant;
int trn(char *str1,char *str2) {
    int i;
    for(i=1; str1[i]!=']'; i++)
        str2[i-1]=str1[i];
    str2[i-1]='\0';
    return i;
}
int cmp1(const void *a,const void *b) {
    return strcmp((*(Enchant**)a)->name,(*(Enchant**)b)->name);
}
int cmp2(const void *a,const void *b) {
    return strcmp((*(Enchant**)a)->content,(*(Enchant**)b)->content);
}
int bsrc1(Enchant **enchant,char *str,int n) {
    int low=0,high=n-1;
    while(low<=high) {
        int t=strcmp(str,enchant[(low+high)/2]->name);
        if(t==0)
            return (low+high)/2;
        if(t>0)
            low=(low+high)/2+1;
        else
            high=(low+high)/2-1;
    }
    return -1;
}
int bsrc2(Enchant **enchant,char *str,int n) {
    int low=0,high=n-1;
    while(low<=high) {
        int t=strcmp(str,enchant[(low+high)/2]->content);
        if(t==0)
            return (low+high)/2;
        if(t>0)
            low=(low+high)/2+1;
        else
            high=(low+high)/2-1;
    }
    return -1;
}
int main() {
    Enchant *enchant1[100000];
    Enchant *enchant2[100000];
    char str[104];
    int count=0;
    scanf("%[^\n]%*c",str);
    while(str[0]!='@') {
        enchant1[count]=(Enchant*)malloc(sizeof(Enchant));
        int i=trn(str,enchant1[count]->name);
        int j;
        for(i+=2,j=0; str[i]!='\0'; i++,j++)
            enchant1[count]->content[j]=str[i];
        enchant1[count]->content[j]='\0';
        enchant2[count]=enchant1[count];
        count++;
        scanf("%[^\n]%*c",str);
    }
    qsort(enchant1,count,sizeof(Enchant*),cmp1);
    qsort(enchant2,count,sizeof(Enchant*),cmp2);
    int n;
    scanf("%d%*c",&n);
    for(int i=0; i<n; i++) {
        scanf("%[^\n]%*c",str);
        if(str[0]=='[') {
            trn(str,str);
            int t=bsrc1(enchant1,str,count);
            if(t==-1)
                printf("what?\n");
            else
                printf("%s\n",enchant1[t]->content);
        } else {
            int t=bsrc2(enchant2,str,count);
            if(t==-1)
                printf("what?\n");
            else
                printf("%s\n",enchant2[t]->name);
        }
    }
    return 0;
}

编辑于 2020-03-19 13:13:30 回复(0)
#include<iostream>
(720)#include<cstdio>
#include<map>
(747)#include<string>

using namespace std;

map<string,string>dictionary;

int main(){
    string str;//循环
    while(getline(cin,str)){
        if(str == "@END@"){
            break;
}
        int pos = str.find("]");
        string key = str.substr(0,pos+1);
        string value = str.substr(pos + 2);
        dictionary[key] = value;
        dictionary[value] = key;//双向映射;
}
    int n;
    scanf("%d",&n);
    getchar();
    while(n--){
        string key;
        getline(cin,key);
        string answer = dictionary[key];// new key;
        if(answer == ""){
            answer = "what?";
        }else if(answer[0] == '['){
            answer = answer.substr(1,answer.size() - 2);
}
        cout<<answer<<endl;
            
        }
        
        return 0;
        
    }
    

王道考研上的做法,感觉他做的挺好的!双映射;
发表于 2020-05-11 09:29:35 回复(0)
用例:
[0 12] 2 12
对应输出应该为:
what?
你的输出为:
0 2312

对于测试用例:
(输入)[lumos]
(输出)the summoning charm
如果在map中是以<lumos,the summoning charm>形式存储,即没有存放中括号,然后在输入[lumos]后,先去括号再查找,就会引发如上错误。
但想不明白原因呀,什么样的测试用例会引发此错呢

发表于 2020-03-17 16:21:35 回复(6)
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;

map<string, string>dictionary;

int main() {
    string str;
    while (getline(cin, str) && str != "@END@") {
        int pos = str.find(']');                    //分界点
        string key = str.substr(0, pos + 1);        //魔咒
        string value = str.substr(pos + 2);         //功能
        dictionary[key] = value;    //魔咒映射功能
        dictionary[value] = key;    //功能映射魔咒(双向映射)
    }
    int n;
    cin >> n;
    getchar();      //吃掉回车
    while (n--) {
        string key;
        getline(cin, key);
        string answer = dictionary[key];
        cout << (answer == "" ? "what?" :               //魔咒或功能找不到
                 answer[0] == '[' ?
                 answer.substr(1, answer.size() - 2) :  //魔咒需要删除方括号
                 answer)
             << endl;
    }
    return 0;
}

编辑于 2024-02-20 17:15:35 回复(0)
#include <cstdio>
#include <iostream>
#include <map>

using namespace std;

// 魔咒字典——[魔咒] 对应功能 
int main() {
	map<string, string> dict;
	
	while (true) {
		string str;
		getline(cin, str);
		if (str == "@END@") {
			break;
		}
		
		int pos = str.find("]");
		// substr(start, len)
		string word = str.substr(0, pos+1); // 中括号中的内容
		string info = str.substr(pos+2); // 中括号中的内容
		// word、info 既是关键字又是内容 
		dict[word] = info; 
		dict[info] = word;
	}
	
	int n;
	scanf("%d", &n);
	getchar();// 将换行符吃掉,不然会被当做查找内容 
	for (int i = 0; i < n; i++) {
		string traget;
		getline(cin, traget);// 必须要getline!!!,因为字符串内包含空格!!! 
		if (dict.find(traget) != dict.end()) {// 存在某个魔咒 
			if (traget[0] == '[') {// 若是[开头,则直接输出info 
				cout << dict[traget] << endl;
			}else {	// 将“[]”去掉后再输出 
				string m = dict[traget];
				m = m.substr(1, m.size()-2);
				cout << m << endl;
			}
		}
		else {// 不存在 
			cout << "what?" << endl;
		}
	}
	return 0;
}
//[expelliarmus] the disarming charm
//[rictusempra] send a jet of silver light to hit the enemy
//[tarantallegra] control the movement of one's legs
//[serpensortia] shoot a snake out of the end of one's wand
//[lumos] light the wand
//[obliviate] the memory charm
//[expecto patronum] send a Patronus to the dementors
//[accio] the summoning charm
//@END@
//4
//[lumos]
//the summoning charm
//[arha]
//take me to the sky

发表于 2023-03-27 09:42:18 回复(0)
#include<bits/stdc++.h>
using namespace std;

int main() {
    map<string,string> Map;
    string str;
    while(getline(cin,str)) {
        if(str=="@END@") {
            break;
        }
        int p=str.find("]");
        string key=str.substr(0,p+1);
        string str1=str.substr(p+2);
        Map[key]=str1;
        Map[str1]=key;
    }
    int n;
    cin>>n;
    getchar();
    while(n--) {
        string key;
        getline(cin,key);
        string answer=Map[key];
        if(answer=="") {
            answer="what?";
        }
        else if(answer[0]=='['){
            int p=answer.find(']');
            answer=answer.substr(1,p-1);
        }
        cout<<answer<<endl;
    }
    return 0;
}

发表于 2022-10-12 16:26:53 回复(1)
注意[]里面也有空格不能以空格为分界!!!
#include<iostream>
#include<string>
#include<cstring>
#include<unordered_map>
using namespace std;

int main() {
    string str;
    unordered_map<string,string> d;
    while(getline(cin,str)&&str!="@END@"){
        int pos = str.find("]");
        string key = str.substr(0,pos+1);
        string value = str.substr(pos+2);
        d[key] = value;
        d[value] = key.substr(1,key.size()-2);
    }
    int n;
    cin>>n;
    cin.get();
    while(n--){
        string key;
        getline(cin,key);
        string ans = d[key];
        if(ans == "") cout<<"what?"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}

编辑于 2024-03-30 14:25:30 回复(0)
//注意使用getline()函数,如果不是第一次使用且前面有过换行空格时,需要利用cin.ignore()函数清空缓冲区
#include <iostream>
#include<unordered_map>
#include<string>
using namespace std;

int main() {
    string str;
    unordered_map<string,string>dic;//word -> def
    unordered_map<string,string>tra;//def ->word
    while(getline(cin,str)){
        if(str=="@END@")break;
        int pos=str.find(']');
        string word=str.substr(1,pos-1);
        string def=str.substr(pos+2);//跳过空格
        dic.insert({word,def});
        tra.insert({def,word});
    }
    int n=0;
    cin>>n;
    cin.ignore();//缓冲区的清空
    while(n--){
        string cur;
        getline(cin,cur);
        if(cur[0]=='['){
            int pos=cur.find(']');
            cur=cur.substr(1,pos-1);
            unordered_map<string, string>::iterator it=dic.find(cur);
            if(it!=dic.end()){
                cout<<it->second<<endl;
            }else{
                cout<<"what?"<<endl;
            }
        }else{
            unordered_map<string, string>::iterator it=tra.find(cur);
            if(it!=tra.end()){
                cout<<it->second<<endl;
            }else{
                cout<<"what?"<<endl;
            }
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")
发表于 2024-03-26 14:10:55 回复(0)
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		List<String> myList = new ArrayList<String>();
		while (scanner.hasNext()) {
			
			while (scanner.hasNext()) {
				String str = scanner.nextLine();
				if (str.equals("@END@")) {
					break;
				}
				myList.add(str);
			}
			
			int n = scanner.nextInt();
			scanner.nextLine();	//消耗换行符
			
			for (int i = 0; i < n; i++) {
				String string = scanner.nextLine();
				
				if (string.charAt(0) == '[') {	//输入的是魔咒
					
					int count = 0;
					for (int j = 0; j < myList.size(); j++) {
						
						String[] strs = myList.get(j).split("]");
							
						if (string.substring(0,string.length()-1).equals(strs[0])) {
							System.out.println(strs[1].substring(1));
							count++;
							break;
						}
		
						
					}
					
					if (count == 0) {	//没有匹配
						System.out.println("what?");
					}
					
					
				}else {	//输入的是功能
					
					int count = 0;
					
					for (int j = 0; j < myList.size(); j++) {
						
						String[] strs = myList.get(j).split("]");
						
						if (string.equals(strs[1].substring(1))) {
							System.out.println(strs[0].substring(1));
							count++;
							break;
						}
					}
					
					if (count == 0) {	//没有匹配
						System.out.println("what?");
					}
					
				}
			}
			
		}
	}
}

编辑于 2024-03-20 17:04:16 回复(0)
import java.util.*;
//以及[咒语]可能含有空格
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Map<String, String> m = new HashMap<>();
        Map<String, String> p = new HashMap<>();
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) {
            String a = in.nextLine();
            if (a.equals("@END@")) break;
            int pos = a.indexOf("]");
            String one = a.substring(1,pos);
            String two = a.substring(pos+2);
            m.put(one, two);
            p.put(two, one);
        }

        int n = in.nextInt();
        in.nextLine();//!!!!!!!!!!!!!!!!!!!注意
        for (int i = 0; i < n; i++) {
            String a = in.nextLine();
            if (a.charAt(0) == ('[')) {
                String tmp = a.split("]")[0].substring(1);
                if (m.containsKey(tmp)) {
                    System.out.println(m.get(tmp));
                    continue;
                } else {
                    System.out.println("what?");
                    continue;
                }
            }
            if (p.containsKey(a)) {
                System.out.println(p.get(a));
            } else {
                System.out.println("what?");
            }


        }
    }
}
编辑于 2024-03-13 17:41:32 回复(0)
#include <iostream>
#include<map>
using namespace std;
int main() {
    string str;
    map<string,string>mymap1;//魔咒->功能
    map<string,string>mymap2;//功能->魔咒
    while (getline(cin,str)) {
        if(str=="@END@")
        break;
        int pos=1;
        while(str[pos]!=']')
        {pos++;}
        string str1=str.substr(1,pos-1);
        string str2=str.substr(pos+2);
        mymap1[str1]=str2;
        mymap2[str2]=str1;


    }
    int n;
    cin>>n;//cin只会吸收行首的换行符,getline把行尾\n变成\0,所以这里必须要加个getchar来吸收换行符
    getchar();//吸收换行符
    string str3;
    for(int i=0;i<n;i++)
    {
        string str3;
        getline(cin,str3);
        map<string,string>::iterator it;
        if(str3[0]=='[')//是魔咒
        {   int pos=1;
           while(str3[pos]!=']')
           {pos++;}
           string str4=str3.substr(1,pos-1);
           it=(mymap1.find(str4));
           if(it==mymap1.end())
           cout<<"what?"<<endl;
           else{
            cout<<mymap1[str4]<<endl;
           }
        }
        else{//功能
        it=(mymap2.find(str3));
        if(it==mymap2.end())
           cout<<"what?"<<endl;
           else{
            cout<<mymap2[str3]<<endl;

        }
    }
    }}
发表于 2023-03-27 16:59:31 回复(0)
#include "map"
#include "iostream"
#include "cstring"
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
const int N = 100010;
map<string, string > cidian ;
int n;
int main() {
    string plus;
    while (getline(cin, plus)) {
        string mozhou, func;
        if (plus == "@END@") break;;
        int p2 = plus.find(']');
        mozhou = plus.substr(0,p2+1);
        func = plus.substr(p2 + 2);
        cidian[mozhou] = func;
        cidian[func] = mozhou;
    }
    scanf("%d", &n);
    getchar();
    while (n--) {
        string test;
        getline(cin, test);
        string ans=cidian[test];
        if (ans=="") {
            ans="what?";
        } else if(ans[0]=='['){
            ans= ans.substr(1,ans.size()-2);
        }
        cout << ans <<endl;
    }

    return 0;
}

发表于 2023-03-18 12:17:55 回复(0)
#include "cstdio"
#include "map"
#include "string"
using namespace std;
int main(){
    map<string,string> dict;
    //构建词典
    while (true){
        char line[200];
        fgets(line,200,stdin);
        string linestr = line;
        linestr.pop_back();//去掉末位'\0'
        if (linestr=="@END@"){
            break;
        }
        string word = linestr.substr(0,linestr.find(']')+1);
        string info = linestr.substr(linestr.find(']')+2);
        dict[word]=info;
        dict[info]=word;

    }
    int N;
    scanf("%d",&N);
    getchar();
    for (int i = 0; i < N; ++i) {
        char line[200];
        fgets(line,200,stdin);
        string string1 = line;
        string1.pop_back();
        if (dict.find(string1) != dict.end()){
            if (string1[0]=='['){
                printf("%s\n",dict[string1].c_str());
            }else{
                printf("%s\n",dict[string1].substr(1,dict[string1].size()-2).c_str());
            }
        } else{
            printf("what?\n");
        }
    }
}

发表于 2023-03-12 20:57:51 回复(0)
import java.util.*;
//有个换行 注意下


// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Map<String,String> map1 = new HashMap<>();
        Map<String,String> map2 = new HashMap<>();
        Scanner in = new Scanner(System.in);
        String curse = in.nextLine();
        while(!curse.equals("@END@")){
            int pos = curse.indexOf(']');
            map1.put(curse.substring(0,pos + 1),curse.substring(pos + 2));
            map2.put(curse.substring(pos + 2),curse.substring(1,pos));
            curse = in.nextLine();
        }
        int n = in.nextInt();
        String blank = in.nextLine();//这里有个换行
        
        for(int i = 0;i<n;i++){
            String word = in.nextLine();
            String res = map1.get(word);
            if(res == null){
                res = map2.get(word);
            }
            System.out.println(res == null ? "What?" : res);
        }

    }
}

发表于 2023-03-08 21:35:48 回复(0)
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        HashMap<String, String> hashMap1 = new HashMap<>(); //<咒语,功能>
        HashMap<String, String> hashMap2 = new HashMap<>(); //<功能,咒语>
        while (in.hasNextLine()) {
            String str = in.nextLine();
            if (!str.equals("@END@")) { //未到结尾处
                String[] split = str.split("]");
                String key = split[0].substring(1);//获取键值
                String value = split[1].substring(1);//获取参数值
                hashMap1.put(key, value);
                hashMap2.put(value, key);
            } else {//到达结尾处
                int n = in.nextInt();//需要输出的个数
                in.nextLine();  //如果要在nextInt()后面再输入一个字符串,就需要加上一个nextLine()用来消除内存中的回车
                for (int i = 0; i < n; i++) {
                    String s = in.nextLine();
                    // System.out.println(s);
                    if (s.contains("[")) {//输出功能
                        String s_key = s.substring(1, s.length() - 1);
                        if (hashMap1.get(s_key) != null)
                            System.out.println(hashMap1.get(s_key));
                        else
                            System.out.println("what?");
                    } else {//输出咒语
                        if (hashMap2.get(s) != null)
                            System.out.println(hashMap2.get(s));
                        else
                            System.out.println("what?");
                    }
                }
                break;
            }

        }

    }
}

发表于 2023-03-08 11:10:31 回复(0)