日期:2014-05-18  浏览次数:20714 次

《微软必应·英雄会第三届在线编程大赛:几个bing?》挑战失败,由于程序运行总时间大于3s导致超时
刚把字符串加到5000左右,确实很慢...这是我的代码:各位大神能帮我简化下吗...
  public static  int howmany(String s)
    {
         int mark=0;
        int x = (int) (Math.pow(10, 9)+7);
    for (int i = 0; i <=s.lastIndexOf("b"); i++) {
         
            int b1 = s.indexOf("b",i);//b
            if(b1!=-1){//有b
                i=b1;//
                for(int j = b1+1;j<=s.lastIndexOf("i");j++){
                    int i1 = s.indexOf("i",j);//i
                    if(i1!=-1){//
                        j=i1;//
                        for(int m=i1+1;m<=s.lastIndexOf("n");m++){
                            int n1 = s.indexOf("n",m);//n
                            if(n1!=-1){//
                                m=n1;//
                                for(int n=n1+1;n<=s.lastIndexOf("g");n++){
                                    int g1 = s.indexOf("g",n);//g
                                    if(g1!=-1){
                                        n=g1;
                                        mark++;
                                    }
                      &n