• 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;
    } 


  • 相关阅读:
    A bon chat, bon rat
    获取信息mysql
    Lua笔记3 表达式
    libevent2编译
    opencv环境搭建
    bash console
    Unix Notes.
    ubuntu vsftpd
    axis2客户端代码生成
    IDEA 快捷键
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7210777.html
Copyright © 2020-2023  润新知