code works fine on my system, but is wrong answer ? ( fibonacci string in beginner )

#include <bits/stdc++.h>

int main()
{
    std::ios::sync_with_stdio( false );
    int n_string;
    std::vector< std::string > strings;
    std::cin >> n_string;
    strings.resize( n_string );
    for ( auto& a : strings )
    {
        std::cin >> a;
    }
    for ( auto& a : strings )
    {
        std::map< char, int > characters;
        std::vector< int > n;
        for ( char c = 'a'; c <= 'z'; ++c )
        {
            characters.insert( std::make_pair( c, 0 ) );
        }
        for( auto& c : a )
        {
            characters.at( c )++;
        }
        for( auto& b : characters )
        {
            if ( b.second == 0) continue;
            n.push_back( b.second );
        }
        std::sort( n.begin(), n.end() );
        bool dynamic = true;
        for ( int i = 2; i < n.size(); ++i )
        {
            if ( n.at( i - 1 ) + n.at( i - 2 ) != n.at( i ) )
            {
                dynamic = false;
                break;
            }
        }
        if ( dynamic ) std::cout << "Dynamic" << std::endl;
        else std::cout << "Not" << std::endl;
    }
}

both “\n” and std::endl produces wrong answer…is for each not supported ? or is it something else and it is related to the output and input ?

first of all you are missing to print :“Dynamic” if n<3 and also after sorting you see n[2] depends on n[1] and n[0] but n[1] and n[0] doesn’t depend on anything so you can change the order of these two so you have to check 2 cases

  1. Normally after sorting the string is “dynamic” or not

  2. After sorting and then swapping n[0] and n[1] is it “dynamic” or not

if after both these cases the boolean variable dynamic in your code is false then the string is not dynamic

hmm…if it is smaller than n < 3, how is it possible to know if the string is dynamic ?
also, I tested the code here CodeChef: Practical coding for everyone and it seems to be have the same output as my code, but it is accepted as correct