Exemple #1
0
int main()
{
    char rawbuf[4096] = {0},buf[4096] = {0},addbuf[1024] = {0};
    char* tmpbuf;

#ifndef ONLINE_JUDGE
    freopen("1.txt","r",stdin);
#endif

    while (fgets(rawbuf,sizeof(rawbuf)-1,stdin) != NULL)
    {
        int leftparent = 0;
        char* ret;

        trimblank(rawbuf,buf);
        tmpbuf = buf;
        calcleftparent(tmpbuf,leftparent);
        while (leftparent)
        {
            fgets(rawbuf,sizeof(rawbuf)-1,stdin);
            trimblank(rawbuf,addbuf);
            tmpbuf = addbuf;
            calcleftparent(tmpbuf,leftparent);
            strcat(buf,addbuf);
        }
        int checksum = atoi(buf);
        char *nodeleftpa = strstr(buf,"(");
        char *noderightpa = buf + strlen(buf)-1;

        Node *root = NULL;
        mknode(nodeleftpa,noderightpa,&root);
        bool flag = false;
        existsum(checksum,root,flag);
        if (flag)
        {
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
        
       releasenode(root); 

    }
    return 0;
}
Exemple #2
0
char* url_in_refresh(const char* content)
{
	if (content == NULL || *content == '\0') //no refresh
		return NULL;
		
	const char* index=content; //cursor to tail string
	
	while (*index == ' ' || *index == 9 || *index == '\n')  //S1
		index++ ; //omit blank symbols
	
	if( !isdigit(*index) && *index != '.' ) //S3
		return NULL;
		
	while( isdigit(*index) || *index == '.' ) // reach time field,S2
		index++; 

	if(*index != ' ' && *index != 9 && *index != '\n' && *index != ';' ) //S5
	{
		char* emp = new char;
		*emp = '\0';
		return emp; //return empty string , indicating refresh oneself
	}
	
	while( *index == ' ' || *index == 9 || *index =='\n' || *index == ';') //S4
		index++;
	
	if ( strncasecmp( "url", index,3) != 0 ) //S5
	{
		char* emp = new char;
		*emp = '\0';
		return emp;  //return empty string , indicating refresh oneself
	}
	
	else //S6
	index = index +3 ;//skip "url'
	while(*index == ' ' || *index == 9 || *index == '\n') //omit blank symbols
		index++;
	if(*index != '=' ) //S5
	{
		char * emp =new char;
		*emp = '\0';
		return emp; //return empty string, indicating refresh oneself
	}
	
	//S7
	index++ ; //skip '='
	while ( *index == ' ' || *index == 9 || *index == '\n' ) //omit blank symbols
		index++;
	if (*index != '\'') //S9
	{
		char* url = strdup(index); //the sub-string from index to the end is url  
		trimblank(url); //trim blank symbols in the end of url;
		return url;
	}
	
	//S8
	index++; //skip '\''
	while (*index == ' ' || *index == 9 || *index == '\n' ) //omit blank symbols
		index++;
	
	//S10
	const char* rquote = strchr(index, '\'') ;// find position of the right single quote
	if (rquote == NULL) // lose right single quote, S12
	{
		char* url = strdup(index); //the sub-string from index to the end is url 
		trimblank(url); //trim blank symbols in the end of url
		return url;
	}
	//S11
	{
		int len = rquote - index; // string length between single quotes
		char* url = new char[len+1];
		memcpy(url, index, len);
		url[len] = '\0';
		trimblank(url);
		return url;
	}
}