cpp没报错 洛谷报错
  • 板块灌水区
  • 楼主杜明泽
  • 当前回复14
  • 已保存回复14
  • 发布时间2022/4/22 20:45
  • 上次更新2023/10/28 03:06:44
查看原帖
cpp没报错 洛谷报错
536707
杜明泽楼主2022/4/22 20:45
/tmp/compiler_u7rkr4xd/src: 在函数‘int main()’中:
/tmp/compiler_u7rkr4xd/src:7:2: 错误:‘gets’ was not declared in this scope; did you mean ‘fgets’?
    7 |  gets(x);
      |  ^~~~
      |  fgets
/tmp/compiler_u7rkr4xd/src:8:15: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
    8 |  for(int i=0;i<strlen(x);i++)
      |              ~^~~~~~~~~~

报错内容(在洛谷里 c++编译器里没报错 以下代码

#include<bits/stdc++.h>

using namespace std;

int main(){

//string x;
char x[1000];
int l=0,d=0,o=0;
gets(x);
for(int i=0;i<strlen(x);i++)
{
	if(x[i]>='a'&&x[i]<='z')
	{
		l++;
		//cout<<x[i]<<"是字母"<<endl; 
	}
	else if(x[i]>='0'&&x[i]<='9')
	{
		d++;
		//cout<<x[i]<<"是数字"<<endl;
	}
	else
	{
		if(x[i]!=' ')
		o++;
		//cout<<x[i]<<"是其他"<<endl;
	}
}
cout<<"Letters="<<l<<endl;
cout<<"Digits="<<d<<endl;
cout<<"Others="<<o-1;
return 0; 

}

2022/4/22 20:45
加载中...