作业2.7_2

麻麻我更委屈了!!!

天平(即风铃)AC代码:两个答案之间空行隔开也就罢了,为嘛最后一行还不能多空行?!

#include<cstdio>
using namespace std; 
bool solve(int &w){
	int w1,d1,w2,d2;
	bool b1=1,b2=1;
	scanf("%d%d%d%d",&w1,&d1,&w2,&d2);
	if(w1==0)b1=solve(w1);
	if(w2==0)b2=solve(w2);
	w=w1+w2;//F=G1+G2; 
	return b1&&b2&&(w1*d1==w2*d2);
}
int main(){
	int t,w;
	scanf("%d",&t);
	while(t--)
	{
		if(solve(w))printf("YES\n");
		else printf("NO\n"); 
		if(t)printf("\n");
	}
	return 0;
}

反片语代码:

#include<bits/stdc++.h>
using namespace std;
map<string,int> cnt;
vector<string>word,ans1;
string s;
string change(string s)
{
	string t=s;
	for(int i=0;i<t.size();i++)
	{
		t[i]=tolower(t[i]);
	}
	sort(t.begin(),t.end());
	return t;
}
int main()
{
	while(cin>>s)
	{
		if(s[0]=='#')break;
		word.push_back(s);
		string ans=change(s);
		if(!cnt.count(ans)) cnt[ans]=0;
		cnt[ans]++;
	}
	for(int i=0;i<word.size();i++)
		if(cnt[change(word[i])]==1)ans1.push_back(word[i]);
	sort(ans1.begin(),ans1.end());
	for(int i=0;i<ans1.size();i++) cout<<ans1[i]<<endl;
	return 0;
}

 

posted @ 2022-02-07 21:32  fervency  阅读(23)  评论(0编辑  收藏  举报