蓝桥杯 算法提高 P1003

 算法提高 P1003  
时间限制:1.0s   内存限制:256.0MB
    
  作为一名网络警察,你的任务是监视电子邮件,看其中是否有一些敏感的关键词。不过,有些狡猾的犯罪嫌疑人会改变某些单词的字母顺序,以逃避检查。请编写一个程序,发现这种调整过顺序的关键词。程序的输入有两行,第一行是关键词列表,第二行是待检查的句子。程序的输出为在该句子中所找到的经过顺序调整的关键词。(单词全部为小写,单词之间以一个空格分隔,每一行的单词个数不限)

输入:
  guns mines missiles
  aameric ssell snug dan iimsssle ot sit neeemis

输出:
  guns missiles


/*
思路: 
原数组,比较数组用来排序 ,然后比较
坑爹?  测试数据输出字符串要按字典序输出? 

对字符串内部字符比较,若比较2个字符串字典序则直接用,跟平常一样 
bool less_lower(char c1, char c2)
{
return c1>c2;
}
sort(str.begin(),str.end(),less_lower);
*/
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstdio>
#include <math.h>
using namespace std;
string s1,s2;
string ss[1000];
string compare[1000];
string re[1000];
bool less_lower(char c1, char c2)
{
     return c1<c2;
}
int main(){    
    int i;
    int len,now;
    string tmp;
    while(getline(cin,s1)&&getline(cin,s2)){
    	len=0;
    	now=0;
    	 tmp="";
    	 for(int i=0;s1[i]!='\0';i++){
    	 	if(s1[i]==' '){
    	 		ss[len]=tmp;  	 	
    	 		sort(tmp.begin(),tmp.end(),less_lower);   
				compare[len++]=tmp;
   	 	       	tmp="";
   	 	      // 	cout<<ss[len-1]<<"       "<<compare[len-1]<<endl;
			 }
			 else
			 {
			 	tmp+=s1[i];
			 }
		 }
		 
		 if(tmp!="")
		   {
		   	ss[len]=tmp;  	 	
    	 	sort(tmp.begin(),tmp.end(),less_lower);   
			compare[len++]=tmp;
		   }
		   
		   tmp="";
		    for(int i=0;s2[i]!='\0';i++){
    	 	if(s2[i]==' '){
    	 		sort(tmp.begin(),tmp.end(),less_lower);  
			//	 cout<<tmp<<endl; 
				 for(int j=0;j<len;j++)
				 	if(compare[j]==tmp)
				 	   re[now++]=ss[j];			 	 
				  		
    	 		tmp="";
			 }
			 else			 
			 	tmp+=s2[i];	
		 }
		 
		 if(tmp!=""){
		 	sort(tmp.begin(),tmp.end(),less_lower);   
			      for(int j=0;j<len;j++)
				 	if(compare[j]==tmp)
				 	  re[now++]=ss[j];	
		 }
		 
		 sort(re,re+now);
		 for(i=0;i<now;i++)
		   cout<<re[i]<<" ";
		 cout<<endl;
	}	
	return 0;
}


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值