Submission #1031968

# Submission time Handle Problem Language Result Execution time Memory
1031968 2024-07-23T09:14:01 Z 7again Laugh Analysis (IOI16_laugh) C++17
Compilation error
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 | }
      | ^