code display #2

Author Avatar
CTS Jan 31, 2018
  • Read this article on other devices

C is an imperative procedural language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory,
to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support.

ACM

#include <stdio.h>
#include <string.h>
char s[200];
int top;
void push(char a)
{
    s[top++]=a;
}
void run()
{
    if(top==1||top==0)
        ;
    else
    {
        if(s[top-1]=='o'&&s[top-2]=='o')
        {
            s[top-2]='O';
            top--;
        }
        if(s[top-1]=='O'&&s[top-2]=='O')
            top-=2;
    }
}
int main()
{
    char k[200];
    int i;
    while(scanf("%s",k)!=EOF)
    {
        top=0;
        for(i=0;i<strlen(k);i++)
        {
            push(k[i]);
            run();
        }
        for(i=0;i<top;i++)
            printf("%c",s[i]);
        printf("\n");
    }
}

This blog is under a CC BY-NC-SA 3.0 Unported License
Link to this article: https://ts-think.github.io/2018/01/31/code-display-2/