编译错误,求助!!
查看原帖
编译错误,求助!!
943699
Alex_Rao楼主2023/6/11 19:05

不明白为啥编译错误了,是比赛禁用gets()和strlower()吗?

/tmp/compiler_2gk_q7vl/src: 在函数‘int main()’中: /tmp/compiler_2gk_q7vl/src:5:9: 错误:‘gets’ was not declared in this scope; did you mean ‘getw’? 5 | gets(in1); | ^~~~ | getw /tmp/compiler_2gk_q7vl/src:8:9: 错误:‘strlwr’ was not declared in this scope; did you mean ‘strstr’? 8 | strlwr(in1) , strlwr(in2); | ^~~~~~ | strstr /tmp/compiler_2gk_q7vl/src:17:26: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] 17 | for(int i = 0; i <= (strlen(s2) - strlen(s1)); i++) { | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /tmp/compiler_2gk_q7vl/src:19:34: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] 19 | for(int j = 0; j < strlen(s1); j++) { |
~~^~~~~~~~~~~~

#include<bits/stdc++.h>
using namespace std;
int main() {
   char in1[12] , in2[1000002];
   gets(in1);
   gets(in2);
   strlwr(in1) , strlwr(in2);
   char s1[2] = " " , s2[2] = " ";
   strcat(in1 , " ");
   strcat(s1 , in1); 
   strcat(in2 , " ");
   strcat(s2 , in2);
   
   int cnt = 0 , idx = 0;
   for(int i = 0; i <= (strlen(s2) - strlen(s1)); i++) {
   	int flag = 1;
   	for(int j = 0; j < strlen(s1); j++) {
   		if(s2[i + j] != s1[j]) {
   			flag = 0;
   			break;
   		}
   	}
   	if(flag == 1) {
   		cnt++;
   		if (cnt == 1) idx = i;
   	}
   }
   
   if(cnt > 0) cout << cnt << " " << idx;
   else cout << -1;
}
     
     
2023/6/11 19:05
加载中...