Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Last active January 2, 2016 20:19
Show Gist options
  • Save KT-Yeh/8355813 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8355813 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string,string>m;
char line[200];
while(gets(line)){
if (line[0]=='\0') break;
char a[50],b[50];
sscanf(line,"%s %s",a,b);
m[b]=a;
}
while(gets(line)){
if (line[0]=='\0') break;
if (m[line]=="\0") //map如果沒對應到,其內容為"\0"
printf("eh\n");
else
printf("%s\n",m[line].c_str()); //把C++字串換回C字串
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment