求程序运行总时间,不太懂解决方案
求程序运行总时间,不太懂
刚刚看无意点进了那个什么英雄会,然后就去做了这道题
《微软必应·英雄会第三届在线编程大赛:几个bing?》
附上链接
http://hero.****.net/Question/Details?ID=215&ExamID=210
下面是我写出来的代码,提交后提示我程序运行总时间大于3S,最后挑战失败。
代码附上
刚刚看无意点进了那个什么英雄会,然后就去做了这道题
《微软必应·英雄会第三届在线编程大赛:几个bing?》
附上链接
http://hero.****.net/Question/Details?ID=215&ExamID=210
下面是我写出来的代码,提交后提示我程序运行总时间大于3S,最后挑战失败。
代码附上
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
public class Test
{
public static long howmany(string s)
{
char[] charList = s.ToCharArray();
List<int> b = new List<int>();
List<int> i = new List<int>();
List<int> n = new List<int>();
List<int> g = new List<int>();
for (int j = 0; j < charList.Length; j++)
{
if (charList[j] == 'b')
b.Add(j + 1);
else if (charList[j] == 'i')
i.Add(j + 1);
else if (charList[j] == 'n')
n.Add(j + 1);
else if (charList[j] == 'g')
g.Add(j + 1);
}
long count = 0;
for (int j = 0; j < b.Count; j++)
{
for (int k = 0; k < i.Count; k++)
{
if (i[k] > b[j])
{
for (int m = 0; m < n.Count; m++)
{
if (n[m] > i[k])
{
for (int t = 0; t < g.Count; t++)
{
if (g[t] > n[m])
{
count++;
}
}
}
}
}
}
}
long sum = count % 1000000007; //对10^9 + 7取余
return sum;
}
public static void Main()
{
Console.WriteLine(howmany("iinbinbing"));