大佬们看看为什么超时了
查看原帖
大佬们看看为什么超时了
224788
w1648476050楼主2021/10/24 11:10
#include <cstdio> 
#include <iostream>
#include <string.h>
using namespace std;
char toLower(char c){
	if(c>='A'&&c<='Z')
	return (c-'A'+'a');
	else return c;
}
int main()
{
	char a[11],b[1000011];
	int count = 0,mark=-1,i,j;
	
	gets(a);
	gets(b);

	bool begin = 1,isequal=1;
	
	for(i=0;i<strlen(b);i++){
		
		if(toLower(a[0])==toLower(b[i])&&(i==0?1:b[i-1]==' ')){
			isequal=1;
			for(j=1;j<strlen(a);j++){
				//cout<<toLower(a[j])<<"--"<<toLower(b[i+j])<<" "; 
				if(toLower(a[j])!=toLower(b[i+j])){
					isequal=0;
					//cout<<b[j];
					break;
				}
			}
			
			
			if(isequal&&(b[i+j]==' '||j==strlen(b))){
				
			
				if(begin){
					mark = i;
					begin=0;	
				}
				
	
				count++;
			}
			
		}
		
	}
	if(count!=0)
	cout<<count<<" ";
	
	cout<<mark;
	
}

主程序最多1000w次应该不会超时的吧,好像读进来好慢,不懂

2021/10/24 11:10
加载中...