LintCode 29. 交叉字符串

给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。

public class Solution {
    /**
     * @param s1: A string
     * @param s2: A string
     * @param s3: A string
     * @return: Determine whether s3 is formed by interleaving of s1 and s2
     */
    public boolean isInterleave(String s1, String s2, String s3) {
        // write your code here
        if(null == s1 || null == s2 || null == s3 || s1.length() + s2.length() != s3.length())
            return false;
        if(s1.length() <= 0 && s2.length() <= 0 && s3.length() <= 0)
            return true;

        boolean[][] common = new boolean[s1.length() + 1][s2.length() + 1];
        for(int i = 1;i <= s1.length();i++)
        {
            if(s1.charAt(i - 1) == s3.charAt(i - 1))
            {
                common[i][0] = true;
            }
        }

        for(int i = 1;i <= s2.length();i++)
        {
            if(s2.charAt(i - 1) == s3.charAt(i - 1))
            {
                common[0][i] = true;
            }
        }

        for(int i = 1;i <= s1.length();i++)
        {
            for(int j = 1;j <= s2.length();j++)
            {
                if(s1.charAt(i - 1) == s3.charAt(i + j - 1))
                {
                    common[i][j] = common[i - 1][j];
                }

                if(common[i][j])
                {
                    continue;
                }

                if(s2.charAt(j - 1) == s3.charAt(i + j - 1))
                {
                    common[i][j] = common[i][j - 1];
                }
            }
        }
        return common[s1.length()][s2.length()];
    }
}

交叉报表字符串溢出问题

02-14

DECLARE @sqlhead nvarchar(4000),@sqlend nvarchar(4000)rn ,@sql1 nvarchar(4000),@sql2 nvarchar(4000),@sql3 nvarchar(4000),@sql4 nvarchar(4000)rn ,@i int,@ic nvarchar(10)rnrn--生成数据处理临时表rnSELECT id=IDENTITY(int,0,1),rn g=0,rn a=CAST(N','rn +QUOTENAME([name])rn +N'=SUM(CASE [name] WHEN N'rn +QUOTENAME(name,N'''')rn +N' THEN [colid] ELSE 0 END)'rn as nvarchar(4000))rnINTO # FROM(rn SELECT DISTINCT name FROM [syscolumns] WHERE name>N'')arnrn--分组临时表rnUPDATE a SET @i=id/i,g=@irnFROM # a,(SELECT i=3800/MAX(LEN(a)) FROM #)brnSET @ic=@irnrn--生成数据处理语句rnSELECT rn @sqlhead=N''''rn +REPLACE(N'SELECT [xtype]',N'''',N'''''')rn +'''',rn @sqlend=N''''rn +REPLACE(N' FROM [syscolumns] GROUP BY [xtype]',N'''',N'''''')rn +N'''',rn @sql1=N'',@sql2=N'',@sql3=N'',@sql4=N''rnWHILE @ic>=0rn SELECT rn @sql1=N',@'+@ic+N' nvarchar(4000)'+@sql1,rn @sql2=N',@'+@ic+N'=N'''''+@sql2,rn @sql3=N',@'+@icrn +N'=CASE g WHEN '+@icrn +N' THEN @'+@ic+N'+a ELSE @'+@icrn +N' END'+@sql3,rn @sql4=N'+@'+@ic+@sql4,rn @ic=@ic-1rnSELECT rn @sql1=STUFF(@sql1,1,1,N''),rn @sql2=STUFF(@sql2,1,1,N''),rn @sql3=STUFF(@sql3,1,1,N''),rn @sql4=STUFF(@sql4,1,1,N'')rnrn--执行rnEXEC(N'DECLARE '+@sql1+N'rnSELECT '+@sql2+N'rnSELECT '+@sql3+N' FROM #rnEXEC(N'+@sqlhead+N'+'+@sql4+N'+N'+@sqlend+N')')rn--删除临时表rnDROP TABLE #rnrn以上代码是邹建写的。rn我有个交叉报表代码想改成以上格式,不会改,谁能帮个忙,谢谢。rndeclare @sql varchar(8000)rnrnset @sql='select 件号=isnull(Item ,null), 件名=isnull(b.cpjm,null) , 重量= ISNULL(b.cpzl,null),制作班组=isnull(b.zzbz,null),合计=isnull(sum(case when flag=1 then Quantity else -Quantity end) ,0)'rnselect @sql=@sql+','+quotename(case when flag=1 then N'入库(' else N'出库(' end +convert(char(10),Riqi,120)+')' )rn+N'=isnull(sum(case when convert(char(10),Riqi,120)='''+convert(char(10),Riqi,120)+N''' and Flag= '+rtrim([Flag])+N' then '+case when Flag=0 then '-' else '' end+N'Quantity end),'''')' from stkc group by Flag,Riqi order by Flag descrnset @sql=@sql+' from stkc a left join cpmx b on a.Item=b.cpjh group by Item,b.cpjm,b.cpZL,b.zzbz'rn--print(@sql)rnexec( @sql)

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试