Problem 55

3 comments on “Problem 55”


  • goutham

    #include
    using namespace std;
    int n;
    string s;
    int main()
    {cin>>n;
    cin>>s;
    int i,total=0,valley=0,count=0;
    for(i=0;i<n;i++)
    {if(s[i]=='u')
    {total++;}
    else
    {if(total==0)
    {valley++;}
    total–;}
    }
    cout<<valley;
    return 0;
    }
    #c++ code


  • sneha

    /******************************************************************************

    Online C Compiler.
    Code, Compile, Run and Debug C program online.
    Write your code in this editor and press “Run” button to compile and execute it.

    *******************************************************************************/
    #include
    #include
    int main()
    {
    int n,x,y,z,v=-1,s=0;
    char a[10];
    scanf(“%d”,&n);
    for(int i=0;i<n;i++)
    {
    scanf("%c",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
    if(a[i]=='U')
    {
    s++;
    }
    else
    {
    if(s==0)
    {
    v++;
    }
    s–;
    }
    //printf("%c",a[i]);
    }
    printf("%d",v);
    return 0;
    }


  • TADEPALLI

    #include
    #include
    int main()
    {
    int n,i,v=0,s=0;
    char arr[15];
    gets(arr);
    n=strlen(arr);
    for(i=0;i<n;i++)
    {
    if(arr[i]=='U')
    s++;
    else
    {
    if(s==0)
    {
    v++;
    }
    s–;
    }
    }
    printf("%d\n",v);
    return 0;
    }