zoukankan      html  css  js  c++  java
  • hdu 1867 A + B for you again

    不懂英文简直要是要死要死要死啊

    首先是谁是谁的字串问题,这个取决于重构的字符串的长度最小

    其次是当不管谁是谁的字串,重构字符串的长度都相等时。去字典序小的重构字符串

    英语不好是硬伤啊

    #include<iostream>
    #include<string>
    #include<algorithm>
    #define maxn 100100 
    using namespace std;
    string str;
    int nextt[maxn];
    void kmp()
    {
    	int l=0,k=-1;
    	nextt[0]=-1;
    	while(l<str.size())
    	{
    		if(k==-1||str[l]==str[k]) nextt[++l]=++k;
    		else k=nextt[k];
    	}
    }
    int solve(string a,string b)//返回字串须要截取掉的位置 
    {
    	str=b;
    	kmp();
    	int i=0,j;
    	if(a.size()>b.size()) j=a.size()-b.size();
    	else j=0;
    	while(j<a.size())
    	{
    		if(i==-1||a[j]==b[i])
    		{
    			i++;j++;
    		}
    		else i=nextt[i];
    	}
    	return i;
    }
    int main()
    {
    	cin.sync_with_stdio(false);
    	string a,b;
    	while(cin>>a>>b)
    	{
    		int x=solve(a,b);
    		int y=solve(b,a);
    		if(x==y)
    		{
    			if(a<b) 
    			{
    				b.erase(0,x);
    				cout<<a<<b<<endl;
    			}
    			else
    			{
    				a.erase(0,y);
    				cout<<b<<a<<endl;
    			} 
    		}
    		else if(x>y)
    		{
    			b.erase(0,x);
    			cout<<a<<b<<endl;
    		}
    		else 
    		{
    			a.erase(0,y);
    			cout<<b<<a<<endl;
    		}
    	}
    	return 0;
    } 


  • 相关阅读:
    Java 测试代码模板
    git 保存用户名和密码
    git 高级命令
    git 最常用命令
    git 冲突解决
    git diff命令
    nginx静态服务器的配置
    使用SFTP工具下载文件
    git log 格式化输出
    9-angular.fromJson
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7210777.html
Copyright © 2011-2022 走看看