日期:2014-05-20 浏览次数:20706 次
public class Test4 {
static char[] ch;
static int index=0;
static int b_num=0;
static int i_num=0;
static int n_num=0;
static int num=0;
public static void main(String[] args) {
System.out.println(getNum("iinbinbinginng"));
}
public static int getNum(String str){
ch=str.toCharArray();
for (int i = 0; i < ch.length; i++) {
switch (ch[i]) {
case 'b':
b_num++;
break;
case 'i':
i_num+=b_num;
break;
case 'n':
n_num+=i_num;
break;
case 'g':
num+=n_num;
break;
default:
break;
}
}
return num%(10^9+7);
}
}
int howmany (const char* s)
{
unsigned int len = 0;
const char* e = s;
const char* key = "bing";
const char* ke = key;
unsigned int keyLen = 0;
long long num = 0;
long long* bing = 0;
int idx[256] = {0};
unsigned int i = 0;
if(s == 0
------解决方案--------------------
*s == 0) return 0;
while(*ke++ != 0);
while(*++e != 0);
keyLen = ke - key - 1;
bing = (long long*)malloc(sizeof(long long) * keyLen);
for(i = 0; i < keyLen; ++i)
{
idx[key[i]] = i + 1;
bing[i] = 0;
}
for (--e; e >= s; --e)
{
int n = idx[*(unsigned char*)e];
if(!n)
continue;
if(n == keyLen)
{
bing[n - 1]++;
}
else
{
if(bing[n] > 0)
bing[n - 1] += bing[n];
}
}
num = bing[0];
free(bing);
return num % 1000000007;
}