답안 #1031968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031968 2024-07-23T09:14:01 Z 7again Laugh Analysis (IOI16_laugh) C++17
컴파일 오류
0 ms 0 KB
#include "laugh.h"

using namespace std ;
int longest_laugh(string s)
{
    int n = s.size() ;
    int mx = 0 ;
    int ans[n]{0} ;
    for(int i = 1 ; i < n ; i++)
    {
        if(s[i] == 'a' & s[i - 1] == 'h')
        {
            ans[i] += ans[i - 1] ;
            ans[i]++ ;
        }
        else if(s[i] == 'h' && s[i - 1] == 'a')
        {
            ans[i] += ans[i - 1] ;
            ans[i]++ ;
        }
        else
        {
            ans[i] = 0 ;
        }
        mx = max(mx  , ans[i]) ;
    }

    if(mx == 0)
    {
        cout << 0 ;
        return ;
    }
    cout << mx + 1 ;
}

Compilation message

laugh.cpp: In function 'int longest_laugh(std::string)':
laugh.cpp:11:17: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   11 |         if(s[i] == 'a' & s[i - 1] == 'h')
laugh.cpp:30:9: error: 'cout' was not declared in this scope
   30 |         cout << 0 ;
      |         ^~~~
laugh.cpp:2:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include "laugh.h"
  +++ |+#include <iostream>
    2 | 
laugh.cpp:31:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
   31 |         return ;
      |         ^~~~~~
laugh.cpp:33:5: error: 'cout' was not declared in this scope
   33 |     cout << mx + 1 ;
      |     ^~~~
laugh.cpp:33:5: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
laugh.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^