luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/POSPROD #837

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Chi tiết bài tập - Luyện Code Online

https://oj.luyencode.net/problem/POSPROD

danh2006 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

#include #define ll long long using namespace std; int a[10000]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n]; for(int i=0;i> a[i]; } int cnt = 0, cnt2 = 0; for(int i=0;i0){ cnt++; }else if(a[i]<0){ cnt2++; }else{ cout << "-1" << endl; return 0; } } if(cnt==0 || cnt2==0){ cout << "0"; }else{ if(cnt

thinh12012007 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

include <bits/stdc++.h>

using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie();cout.tie(); int n;cin>>n;int a[n]; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n);

 int dem1=0,dem2=0,dem=0;
 for(int i=1;i<=n;i++){
     if(a[i]==0) {dem=-2;break;}
     else if(a[i]<0) dem++;
  }
  if(dem==-2) cout<<-1;else if(dem==n) cout<<0;
  else if(dem>n-dem) cout<<n-dem;
  else if(dem==0) cout<<0;else cout<<dem;
return 0;

}