START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i’m fiwo riwosf.
i fiiwj fnnvk!
END
Sample Output
hello, i’m from mars.
i like earth!
题目大意 将一个单词 转换为 另一单词
代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#define LL long long
#define M 10000
#define inf 0x3f3f3f3f
#define mod 100009
using namespace std;
map<string,string>mp;
char tmp[3000+100];
int main()
{
string a,b; //
cin>>a; // start cin 遇到空格断,且可以自动过滤回车
while(cin>>a&&a!="END")
{
cin>>b; // string 只能够用 cin 来获取
mp[b]=a;
}
cin>>a; // 吃start
getchar(); // 吃回车
//只有在输入数字 和 用gets()之间是要用getchar吃空行的,对于连续多个用gets输入,,会自动吃空行的
while(1)
{
gets(tmp); // 这里就是多次连续输入 gets ,但是却不用吃空行
if(strcmp(tmp,"END")==0) break;
int i,len;
len=strlen(tmp);
b=""; // 清空string b
for(i=0;i<len;i++)
{
if(!(tmp[i]>='a' && tmp[i]<='z'))//非小写字母
{
if(mp[b]!="") //存在这个单词
cout<<mp[b];
else cout<<b;
b="";
cout<<tmp[i];
}
else //小写字母
b+=tmp[i]; // 这个很方便
}
cout<<endl; // 换行
}
return 0;
}
Sample Input
1
5
apple shandong 3
pineapple guangdong 1
sugarcane guangdong 1
pineapple guangdong 3
pineapple guangdong 1
Sample Output
guangdong
|—-pineapple(5)
|—-sugarcane(1)
shandong
|—-apple(3)
代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#define LL long long
#define M 10000
#define inf 0x3f3f3f3f
#define mod 100009
using namespace std;
map<string, map < string , int > > mp; // 嵌套 中间一定要有一些 空格
map< string , map < string , int > >::iterator it1;
map<string,int >::iterator it2; //map 中可以将 原像 和 像都 输出出来 it2.first it2.second
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int m;
scanf("%d",&m);
mp.clear();
while(m--)
{
string a,b;int num;
cin>>a>>b>>num;
mp[b][a]+=num;
} // map 中存储时候,是按照 原像 的字典序存储的,
for(it1=mp.begin();it1!=mp.end();it1++)
{
cout<<it1->first<<endl;
for(it2=it1->second.begin();it2!=it1->second.end();it2++)
{
cout<<" |----"; // C++中 endl 代表了换行
cout<<it2->first<<"("<<it2->second<<")"<<endl;
}
}
if(t) putchar('\n');
}
return 0;
}