723B - Text Document Analysis - CodeForces Solution


expression parsing implementation strings *1100

Please click on ads to support us..

Python Code:

_len=int(input())
_str=input().replace('(',')!').split(')')
_str=list(filter(None,_str))
mxLen,wordsNum=0,0
for word in _str:
    if word[0]=='!':
        words=word[1:].split('_')
        words=list(filter(None,words))
        wordsNum+=len(words)
    else:
        words=word.split('_')
        mxLen=max(mxLen,len(max(words,key=len)))
print(mxLen,wordsNum)

C++ Code:

#include <bits/stdc++.h>
using ll = long long;
#define Shalaby ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
#define endl '\n'
#define Endl '\n'
#define nl cout << '\n'
#define pb(x) push_back(x)
#define all(v) v.begin(), v.end()
bool y_n(bool t)
{
    cout << ((t) ? "YES\n" : "NO\n");
}
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    string c = "";
    int ans = 0, cntr = 0;
    bool check = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '(')
        {
          //  cout << c << endl;
            ans = max(ans, int(c.size()));
            c = "";
            check = 1;
            continue;
        }
        else if (s[i] == ')')
        {
            if (c != "")
                cntr++;
            check = 0;
            c = "";
            continue;
        }
        if (check)
        {
            if (s[i] != '_')
                c += s[i];
            else
            {
               // cout << c << endl;
                if (c != "")
                {
                    cntr++;
                }
                c = "";
            }
        }
        else
        {
            if (s[i] != '_')
                c += s[i];
            else
            {
                //cout << c << endl;
                ans = max(ans, int(c.size()));
                c = "";
            }
        }
    }
   // cout << c << endl;
    ans = max(ans , int(c.size()));
    cout << ans << ' ' << cntr << endl;
}
int main()
{
    Shalaby;
    //    freopen("mex.in", "rt", stdin);
    int n = 1;
    // cin >> n;
    while (n--)
    {
        solve();
    }
}
/*

*/


Comments

Submit
0 Comments
More Questions

961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza
731A - Night at the Museum
742A - Arpa’s hard exam and Mehrdad’s naive cheat
1492A - Three swimmers