Vị trí số âm
code cho ai cần:
#include <bits/stdc++.h>
#define ll long long
const int N=1e7+2;
using namespace std;
ll n,a[N],dau,cuoi,d;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
cin >> n;
for(ll i=1;i<=n;i++)
{
cin >> a[i];
if(a[i]<0)d++;
}
if(d>0)
{
for(ll i=1;i<=n;i++)
{
if(a[i]<0){cout << i << " ";break;}
}
for(ll i=n;i>=1;i--)
{
if(a[i]<0){cout << i << " ";break;}
}
}else cout << -1 << " " << -1;
return 0;
}
...Xem thêm
Chẵn lẻ
hint
tạo hàm kiểm tra xâu nếu: b+c mà lẻ =>no
nếu ko thì => yes
(
b = vị trí từng phần tử của a
c = phần tử ở vị trí b của a
)
...Xem thêm
Bạn có phải là robot không?
include <bits/stdc++.h>
using namespace std;
int main() {
cout << "LQDOJ" << endl;
return 0;
}
c++
...Xem thêm
Làm (việc) nước
include <bits/stdc++.h>
using namespace std;
double a,b,s[5];
int main()
{
cin >> a >> b;
for(int i =1 ; i<= 4;i++){
s[1]=a+b;
s[2]=a-b;
s[3]=a*b;
s[4]=a/b;
sort(s+1,s+5,greater<double>());
cout << fixed << setprecision(6) << s[i] << " ";
}
return 0;
}
...Xem thêm