牛客应该禁用gets了-取代方法
字符串链接
http://www.nowcoder.com/questionTerminal/9f27c74ec91e4c7da96ba351dba235fc
一、情况
#include<bits/stdc++.h> using namespace std; static const int maxn=1e5+5; char a[maxn]; char b[maxn]; char solve[maxn]; void MyStrcat(char dstStr[],char srcStr[]) { int tag=0; int lenA=strlen( dstStr ); int lenB=strlen( srcStr ); for(int i=0; i<lenA; ++i) { char c=dstStr[i]; if( ' '!=c ) { solve[tag++]=c; } } for(int i=0; i<lenB; ++i) { char c=dstStr[i]; if( ' '!=c ) { solve[tag++]=c; } } } int main() { while( nullptr!=gets(a) ) { gets(b); MyStrcat(a,b); printf("%s\n",solve); } return 0; }
编译错误:您提交的代码无法完成编译 a.cpp:37:21: error: use of undeclared identifier 'gets' while( nullptr!=gets(a) ) ^ a.cpp:39:9: error: use of undeclared identifier 'gets' gets(b); ^ 2 errors generated.
二、取代gets的东西(记忆)ACda
#include<bits/stdc++.h> using namespace std; static const int maxn=1e5+5; char a[maxn]; char b[maxn]; void MyStrcat(char dstStr[],char srcStr[]) { int tag=0; int lenA=strlen( dstStr ); int lenB=strlen( srcStr ); for(int i=0; i<lenA; ++i) { char c=dstStr[i]; if( ' '!=c ) { a[tag++]=c; } } a[tag]='\0'; tag=0; for(int i=0; i<lenB; ++i) { char c=srcStr[i]; if( ' '!=c ) { b[tag++]=c; } } b[tag]='\0'; } int main() { while( ~scanf("%[^\n]",a) ) { getchar();//注意,一定要吸收'\n',这样,被禁用的'\n'就能OK了 scanf("%[^\n]",b); MyStrcat(a,b); printf("%s\n",a); printf("%s\n",b); getchar();//注意,一定要吸收'\n',这样,被禁用的'\n'就能OK了 //break; } return 0; }