问题遇到的现象和发生背景
写题时,Dev-C++突然坏了,于是我换成了C-free,代码如下:
问题相关代码,请勿粘贴截图
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
const int N=1e6+5;
//put your deta here
int a[N];
int twice(int a[],int l,int r,int x){
while(l<r){
int m=(l+r)/2;
if(a[m]==x){
return m;
}
else if(a[m]>x){
r=m;
}
else{
l=m+1;
}
}
return -1;
}
int main() {
//put your code here
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
while(m--){
int x;
cin>>x;
cout<<twice(a,1,n+1,x)<<"\n";
}
return 0;
}
运行结果及报错内容
报错:
--------------------配置: mingw2.95 - CUI Debug, 编译器类型: MinGW (Old)--------------------
正在编译 E:\Program Files (x86)\C-Free Standard\temp\未命名3.cpp
[Error] g++.exe: cannot specify -o with -c or -S and multiple compilations
编译中止 E:\Program Files (x86)\C-Free Standard\temp\未命名3.cpp: 1 个错误, 0 个警告
我的解答思路和尝试过的方法
代码能运行,所以我觉得是编译器的问题
我想要达到的结果
有没有哪个人能看出来错啊!