摘要:这是我水的第二道KMP题目。。。 哈哈 用了输入外挂187MS水过#include<stdio.h>int num1[1000005],num2[10005],next[10005],n,m;void getnext( ){ int i = 0,j = -1; next[0] = -1; while( i < m ) { if( j == -1 || num2[i] == num2[j] ) ++i,++j,next[i] = j; else j = next[j]; }}int KMP( ){ int i = 0, j = 0; while( i < n &&
阅读全文
摘要:这个要注意把缩写的最后一个字符串置为0#include<stdio.h>#include<string.h>#include<ctype.h>char str[1000],s[1000];int main( ){ int t; scanf( "%d%*c",&t ); while( t-- ) { gets( str ); int i = 0,c = 0; while( str[i] ) { if( !isalpha( str[i] ) ) { ++i; continue; } if( str[i] > 'Z'
阅读全文
摘要:这题深受北大那题影响啊,这是链接http://www.cnblogs.com/Lvsi/archive/2011/04/10/2011484.html这题要注意happy的顺序不能变,所以要最先产生h然后a然后p,p,y,给每个字母都对应一个数组的数,要产生a时必须有h,要产生p时必须有a,要产生happy时,必须有一个h,一个a,两个p,一个y;而且要保证所有的happy都没颠倒次序,所以每一个字母的个数不能超过前面那个字母的个数( 例如hayppahppy,这种只有一个 )#include<stdio.h>#include<string.h>int n,num[5]
阅读全文
摘要:这里跟前面两个字符串处理差不多,http://www.cnblogs.com/Lvsi/archive/2011/05/03/2035640.htmlhttp://www.cnblogs.com/Lvsi/archive/2011/05/04/2036156.html#include<stdio.h>#include<string.h>int n;char str[10005],ch[1005][1005];void sort( ){ int i = 0; while( str[i] ) { if( str[i] == ' ' ) { ++i; cont
阅读全文
摘要:这题一水题 .... 据说可以用函数做 ( strtok) ,没用,没看懂,自己写了一个.. 水果,不过记住中间有很多空格要原样输出......还有把字符串分开后,在每个后面都得赋值ASCII为0额#include<stdio.h>#include<string.h>int n,c;char str[1005],ch[1005][1005];void sort( ){ int i = 0; while( str[i] ) { int j = 0; while( str[i] == ' ' ) ch[c][j++] = str[i++]; ch[c][j]
阅读全文
摘要:简单排序,这里先把一个字符串按5来分成很多字符串,然后对这些字符串进行比较#include<stdio.h>#include<string.h>#include<stdlib.h>int n;char str1[1005],str2[1005][1005];void sorts( )//将字符串分成很多个{ memset( str2,0,sizeof( str2 ) ); int i = 0; while( str1[i] ) { if( str1[i]&&str1[i] == '5' )//处理前面多余的5 { ++i; c
阅读全文
摘要:在这里我找到了找字符串子串的一种好方法,下面介绍给大家I:我爱你啊查看提交统计提问时间限制:1000ms内存限制:65536kB描述ftiasch是个十分受女生欢迎的同学,所以她总是收到许多情书。虽然她十分有魅力,然而她却是个低调的人。因此她从来不会告诉别人她到底收到了多少情书。ftiasch的好朋友1tthinking想知道她到底收到了多少情书。1tthinking知道,ftiasch每次收到一封情书,就会在日记最后写下一个包含"luvletter"子序列的串。比如现在ftiasch的日记是alduddvdletterflusvletetedr,那么ftiasch可能受到
阅读全文
摘要:JAVAimport java.io.*;import java.util.*;import java.math.*;import java.io.BufferedInputStream; public class aa{ public static void main( String[] args ) { BigDecimal a,b; Scanner cin = new Scanner(System.in); while( cin.hasNext() ) { a = cin.nextBigDecimal(); b = cin.nextBigDecimal(); a = a.stripTra
阅读全文
摘要:KMP算法入门题 哥第一次写KMP惭愧啊,惭愧getnext写得蛋痛,后面的KMP部分更蛋痛。改了N久#include<stdio.h>#include<string.h>#define Max 1005char str[Max+5] = {0},ch[Max+5] = {0};int next[Max+5],count = 0,n;void getnext( ){ int i = 0,j = -1; next[0] = -1; while( ch[i] ) { if( j == -1 || ch[i] == ch[j] ) ++i,++j,next[i] = j; e
阅读全文