快捷导航

求问这个程序哪里有问题?

Binary String Matching时间限制:3000ms | 内存限制:65535KB难度:3描述Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110110’ while the pattern string A is ‘11’, you should output 3, because the pattern A appeared at the posit输入The first line consist only one integer N, indicates N cases follows. In each case, there are two lines, the first line gives the string A, length (A) 1000){                System.out.println("Wrong!");                break;        }                else        System.out.println(count(s1,s2));}}publicstaticintcount(Strings1,Strings2){        intnum=0;                for(inti=0;i

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员2

s2.substring(i,j)==s1,这句话有问题,.substring(start,end)表示的是开始到结束的下标位置
如果你是想比较a在b匹配的个数的的话,那么每次a的长度是不变的,可以选择.substr(start,number)
表示的是开始位置,和要截取的字符串长度


===========================================================
貌似回答的有点问题,java里没有.substr()方法,可以用.substring(start,start+number)代替
回复

使用道具 举报

字符串比较不能用== 要用equals
if(s2.substring(i,j).equals(s1))
回复

使用道具 举报

可能感兴趣的问答

发新帖
TA的信息
  • 会员所属: 注册会员
  • 认证信息: 邮箱认证手机认证
  • 微信访问
  • 手机APP