全TLE,不知哪里有问题。
查看原帖
全TLE,不知哪里有问题。
735164
pengqiushi楼主2022/7/29 19:16

代码如下:

#include<cstring>
using namespace std;
char a[15],ans[15];
void tydxx(){
   for(int i=0; i<=strlen(a); i++)
   	if(a[i]>='A'&&a[i]<='Z')
   		a[i]+=32;
}
int cmp(){
   for(int i=0; i<=9; i++)
   	if(ans[i]!=a[i])
   		return 0;
   return 1;
}
int main()
{
   char t; //统计单词什么时候输入完。 
   scanf("%s",ans); //输入目标单词。 
   for(int i=0; i<=strlen(ans); i++)
   	if(ans[i]>='A'&&ans[i]<='Z')
   		ans[i]+=32; //统一单词大小写。 
   int c=0,cs=0,p; //c:正确单词个数。 
   while(1){       //cs:第几个单词。 
   	scanf("%s",a); 
   	cs++;
   	t=getchar();//读入单词后面是否为换行 
   	if(t=='\n'||t=='\r')
   		break; //如果是,则结束读入。 
   	tydxx(); //统一单词大小写。
   	if(cmp()==1) 
   		c++; //该代码的语言。 
   	if(c==1&&cmp()==1)
   		p=cs;
   }
   if(c==0)
   	cout<<"-1";
   else printf("%d %d",c,p-1);
   return 0;
}

样例全过,自己编也全过,下面是编的样例:

1.in
DO
Do you do homework in the classroom
1.out
2 0
2.in
ThE
Let is go to the library
2.out
1 4

评测记录:https://www.luogu.com.cn/record/81698950

2022/7/29 19:16
加载中...