zoukankan      html  css  js  c++  java
  • uva 409 WA!!!哪里错了?

    //各位看看哪里不对。。。WA啊!
    #include <stdio.h>
    #include <string.h>
    int nkey;
    int nexc;
    
    char keywords[30][30];
    char excuses[30][100];
    int  excTimes[30];
    
    int findInexc(int order)
    {
    	int i,j,k,key_len,exc_len;
    	char str[100];
    	strcpy(str,excuses[order]);
    	exc_len=strlen(str);
    
    	for(i=0;i<exc_len;i++)//借口全部转换为小写
    	{
    		if('A'<=str[i] && str[i]<='Z')
    			str[i]=str[i]+32;
    	}
    
    	for(i=0;i<nkey;i++)//遍历每个关键字,在excuses[order]中寻找,若找到了,则excTimes[order]++
    	{
    		key_len=strlen(keywords[i]);
    		for(j=0;j<exc_len;j++)
    		{
    			for(k=0;k<key_len;k++)
    			{
    				if(keywords[i][k]==str[j+k])
    					continue;
    				else
    					break;
    			}
    			if(k==key_len)
    				excTimes[order]++;
    		}
    	}
    	
    	return 0;
    }
    
    int display()
    {
    	int i,j;
    	for(i=0;i<nexc-1;i++)//先冒泡排序,找出出现的最大的次数
    	{
    		for(j=nexc-1;j>i;j--)
    		{
    			if(excTimes[j]>excTimes[j-1])
    			{
    				int tmp=excTimes[j];
    				excTimes[j]=excTimes[j-1];
    				excTimes[j-1]=tmp;
    
    				char tmpstr[100];
    				strcpy(tmpstr,excuses[j]);
    				strcpy(excuses[j],excuses[j-1]);
    				strcpy(excuses[j-1],tmpstr);
    			}
    		}
    	}
    
    	i=0;//输出最大次数对应的借口
    	do
    	{
    		printf("%s\n",excuses[i]);
    		i++;
    	}while(excTimes[i]==excTimes[i-1] && i<nexc);//如果有并列最大的则也输出
    
    	return 0;
    }
    int main()
    {
    	int i,j=1;
    
    	while(scanf("%d %d",&nkey,&nexc)!=EOF)
    	{
    		memset(excTimes,0,sizeof(excTimes));//初始化数组为0,这个数组表示每个关键字在每句话中出现的次数
    		for(i=0;i<nkey;i++)
    			scanf("%s",keywords[i]);
    		getchar();
    		for(i=0;i<nexc;i++)
    			gets(excuses[i]);
    
    		for(i=0;i<nexc;i++)
    			findInexc(i);//开始构造excTimes数组
    
    		
    
    		printf("Excuse Set #%d\n",j);
    		j++;
    		display();//显示结果
    			
    		printf("\n");
    	}
    	return 0;
    }
    

  • 相关阅读:
    jaxb 专题一(JAXB 实现java对象与xml之间互相转换)
    spring @Transactional注解参数详解
    Spring声明式事务管理与配置详解
    spring源码解析--事务篇(前篇)
    Java的三种代理模式
    Spring AOP面向切面编程详解
    Spring AOP基于注解的“零配置”方式实现
    Spring AOP 中pointcut expression表达式解析及配置
    Spring AOP详解
    一种解决maven单继承的办法
  • 原文地址:https://www.cnblogs.com/exlsunshine/p/3775107.html
Copyright © 2011-2022 走看看