ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1345. HTML

I don't get it.
Posted by Artem Berezovsky 25 May 2015 18:50
What is test 2? I can't think of anymore tests, it's really killing me.
Here is my code, if you can see a mistake, please tell me.
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<cctype>
#include<memory.h>

char keywords[35][64] = {{'a','n','d'},{'a','r','r','a','y'},{'b','e','g','i','n'},{'c','a','s','e'},{'c','l','a','s','s'},{'c','o','n','s','t'},{'d','i','v'},{'d','o'},{'e','l','s','e'},{'e','n','d'},{'f','o','r'},{'f','u','n','c','t','i','o','n'},{'i','f'},{'i','m','p','l','e','m','e','n','t','a','t','i','o','n'},{'i','n','t','e','r','f','a','c','e'},{'m','o','d'},{'n','o','t'},{'o','f'},{'o','r'},{'p','r','o','c','e','d','u','r','e'},{'p','r','o','g','r','a','m'},{'r','e','c','o','r','d'},{'r','e','p','e','a','t'},{'s','h','l'},{'s','h','r'},{'s','t','r','i','n','g'},{'t','h','e','n'},{'t','o'},{'t','y','p','e'},{'u','n','i','t'},{'u','n','t','i','l'},{'u','s','e','s'},{'v','a','r'},{'w','i','t','h'},{'w','h','i','l','e'}};
char s[1024][256];

bool IsKeyword(char y[256])
{
    int j = 0;
    bool itis = false;
    for(int i = 0; i<35; i++)
    {
        if(tolower(y[0]) == keywords[i][0] && strlen(y) == strlen(keywords[i]))
        {
            for(j = 1; j<strlen(y); j++)
            {
                itis = false;
                if(tolower(y[j]) != keywords[i][j])
                    break;
                itis = true;
            }
        }
        if(itis && !((s[i][j+1] >='a' && s[i][j+1]<='z') || (s[i][j+1] >='A' && s[i][j+1] <='Z')))
        {memset(y,0,sizeof(y));return true;}
    }
    memset(y,0,sizeof(y));
    return false;
}

int main()
{
    int x,y;
    int strings = 0;
    int skip = 0;
    int i = 0;
    bool was;
    while(gets(s[i++])!=0) strings++;
    for(int i = 0;i<strings; i++)
    {
        int j = 0;
        was = false;
        if(strlen(s[i]) == 0)
            {printf("\n");continue;}
        for(j; j<strlen(s[i]);j++)
        {
            if(s[i][j]>='0' && s[i][j]<='9' && (s[i][j-1] == '=' || s[i][j-1] == ' ' || j == 0))
            {
                printf("<span class=number>");
                int numdots = 0;
                while((s[i][j] >='0' && s[i][j] <='9') || (s[i][j] == '.' &&  numdots < 2 && (s[i][j+1] >='0' && s[i][j+1] <='9')))
                {
                    printf("%c", s[i][j]);
                    j++;
                    if(s[i][j] == '.')
                        numdots++;
                }
                j--;
                if(j == strlen(s[i]))
                    {if(s[i][j] == '.')
                        printf("</span>.\n");
                    else
                        printf("</span>.\n");
                    continue;}
                else
                    {if(s[i][j] == '.')
                        printf("</span>.");
                    else
                        printf("</span>");
                    continue;}
                j--;
                continue;
            }
            if((s[i][j] >='a' && s[i][j]<='z') || (s[i][j] >='A' && s[i][j] <='Z'))
            {
                char insert[64];
                int len = 0;
                for(int k = j; k<strlen(s[i]); k++)
                {
                    if((s[i][k] >='a' && s[i][k]<='z') || (s[i][k] >='A' && s[i][k] <='Z'))
                    {
                        memset(insert,0,sizeof(insert));
                        len = 0;
                        while((s[i][k] >='a' && s[i][k]<='z') || (s[i][k] >='A' && s[i][k] <='Z') || (s[i][k]>='0' && s[i][k]<='9'))
                        {insert[len++] = s[i][k];k++;}
                        if(IsKeyword(insert))
                        {
                            printf("<span class=keyword>");
                            for(j; j<k; j++)
                                printf("%c", s[i][j]);
                            if(len == strlen(s[i]))
                                printf("</span>");
                            else
                                printf("</span>");
                            break;
                        }
                        //else
                        //{
                        //    for(j;j<=k;j++)
                        //        printf("%c", s[i][j]);
                        //}
                    }
                    else
                        break;
                }
            }
            if(s[i][j] == '{' || (s[i][j] == '/' && s[i][j+1] == '/'))
            {
                if((s[i][j] == '{' && skip == 0))
                {
                    j++;
                    printf("<span class=comment>{");
                    for(int k = j; k<strlen(s[i]); k++)
                    {
                        j = k;
                        if(s[i][k] == '{')
                            skip++;
                        if(s[i][k] == '}')
                        {
                            if(skip == 0)
                            {printf("}</span>");j++;break;}
                            else
                            {skip--;}
                        }
                        printf("%c", s[i][k]);
                            if(k == strlen(s[i])-1)
                        {i++; k = -1;printf("\n");}
                    }
                }
                else
                    {
                        printf("<span class=comment>");
                        for(j;j<strlen(s[i]);j++)
                            printf("%c", s[i][j]);
                        j = strlen(s[i]);
                        printf("</span>");}

            }
            if(s[i][j] == '\'' || s[i][j] == '#')
            {
                if(s[i][j] == '\'')
                {
                    j++;
                    printf("<span class=string>\'");
                    int len;
                    while(s[i][j] !='\'')
                    {
                        len = j;
                        printf("%c", s[i][j]);
                        if(j == strlen(s[i])-1)
                        {i++; j = 0; printf("\n"); continue;}
                        j++;
                    }
                    printf("\'</span>");
                    continue;
                }
                else if(s[i][j+1] >= '0' && s[i][j+1] <='9')
                {
                    printf("<span class=string>#");
                    j++;
                    int len;
                    for(int k = j; (s[i][k] >='0' && s[i][k]<='9'); k++)
                    {len = j; printf("%c", s[i][j]);j++;}
                    printf("</span>");
                    j--;
                    continue;
                }
            }
                if((j!=strlen(s[i]) || j!=strlen(s[i])) && was == false)
                printf("%c", s[i][j]);
                if((j >= strlen(s[i])-1))//i != strings-1)
                {printf("\n");}
        }
    }
    //for(int i = 0;;i++);
}