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/STREAK #651

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Tung đồng xu - Luyện Code Online

https://luyencode.net/problem/STREAK

huydh1900 commented 2 years ago

Ai thích có thể tham khảo: https://luyencode.net/status/b0126750d589d8511d87e42565aa0d35?problem=STREAK

Conan286 commented 2 years ago

Code AC: https://github.com/huykhalac/1000baicpp/blob/main/STREAK%20-%20Tung%20%C4%91%E1%BB%93ng%20xu.cpp

mcuongit commented 2 years 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

```cpp #include #include using namespace std; int demSapMatLuon(string a[], int n, string x) { int d = 0; int m = d; for (int i = 0; i < n; i++) { if (a[i] == x && a[i+1] == x) { d++; if (m < d) m = d; } else if (a[i] == x && a[i + 1] != x) { d++; if (m < d) m = d; } else { d = 0; } } return m; } int main() { unsigned int n; cin >> n; string a[50]; for (int i = 0; i < n; i++) { cin >> a[i]; } cout << demSapMatLuon(a, n, "Heads") << " " << demSapMatLuon(a, n, "Tails"); return 0; } ```

kakanvk commented 1 year ago

Code AC dùng Prefix Sum

Xem code AC

```cpp //https://oj.luyencode.net/problem/STREAK #include #include using namespace std; int head=0, tail=0, n; int A[55], B[55]; string s; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=1; i<=n; i++){ cin >> s; if(s == "Heads"){ A[i] = A[i-1] + 1; head = max(head, A[i]); } else { B[i] = B[i-1] + 1; tail = max(tail, B[i]); } } cout << head << " " << tail; return 0; } //Code by kakanvk ```