用户:
寂寞de奶酪查看:101 回复:5 评论:21 创建时间:2023-07-30T18:32:17







小Yiiiii#include<bits/stdc++.h>
using namespace std;
int main(){
char a[100005],b[100005];
int t,ans,n,alen,blen;
cin>>t;
while(t--){
cin>>a>>b;
n=0;
alen=strlen(a);
blen=strlen(b);
a[alen]='0';
b[blen]='0';
for(int i=0;b[i]!=0;i++){
if(a[n]==b[i])n++;
if(n>=alen)break;
}
if(alen!=n){
cout<<"NO";
}else{
cout<<blen-alen;
}
cout<<"\n";
}
return 0;
}
点赞0
评论
昨天竟然没看到
错了×,只对了一部分哦
主要是时间太久的问题
其次就是输出的答案错误
???
我算过时间复杂度,不应该超时啊?
最大的问题时间,之后是答案的输出
小Yiiiii#include<bits/stdc++.h>
using namespace std;
int main(){
char a[100005],b[100005],c[15];
int t=0,ans,n,alen,blen;
gets(c);
for(int i=0;i<strlen(c);i++){
t=t*10+c[strlen(c)-1-i]-'0';
}
while(t--){
gets(a);
gets(b);
n=0;
alen=strlen(a);
blen=strlen(b);
a[alen]='0';
b[blen]='0';
for(int i=0;b[i]!=0;i++){
if(a[n]==b[i])n++;
if(n>=alen)break;
}
if(alen!=n){
cout<<"NO";
}else{
cout<<blen-alen;
}
cout<<"\n";
}
return 0;
}点赞0
评论
我感觉输出不对可能是空格的原因,时间我是真优化不了
废话嘛,输入都得这个时间复杂度捏
啊哦,编译错了哦×
answer.cpp: In function 'int main()': answer.cpp:6:2: error: 'gets' was not declared in this scope; did you mean 'fgets'? 6 | gets(c); | ^~~~ | fgets
第六行
6 | gets(c);
为什么我编译过了?
改成scanf输入即可,gets已被c++11弃用,部分编译器禁止使用
正常现象改成scanf输入即可,gets已被c++11弃用,部分编译器禁止使用
嗯嗯
数组好多 没有2维吗?