Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮忙看看我的代码

Posted by denganliang at 2011-03-28 14:23:27 on Problem 2338
In Reply To:Re:给后来者提供几组测试数据 Posted by:denganliang at 2011-03-28 14:03:07
我已经提供数据了,但是我的还是wa,大家帮忙看看我的代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char str[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
char s[100];
int test(int n,char ch){
	int i;
	for(i=0;i<n;i++){
		if(str[i]==ch) return 1;
		}
	return 0;
	}
int change(int b,int i)	{
	char base[100];
	int k,j,len,r,temp;
	int num[100]={0};
	k=0;
	memset(base,'\0',81);
	for(j=i-3;j>-1;j--)
          if(s[j]=='#') break;
    for(i=j+1;i<strlen(s);i++){
		if(s[i]=='#') break; 
		base[k++]=s[i];
		}	
    for(i=0;i<strlen(base);i++)
    {
		for(j=0;j<16;j++)
           if(base[i]==str[j])
            num[i]=j;		
		}
	len=strlen(base);
			r=0;
    for(i=len;i>0;i--)
    {
		temp=1;
		
		for(j=0;j<i-1;j++)
          temp*=b;
        if(i==1) temp=1;
		r+=num[len-i]*temp;
		}
		return r;
	}
int main(){
	int i,j,k,n,b,len,count,flag;
	char base[100],ss[100];
	scanf("%d",&n);
	for(k=0;k<n;k++){
		memset(s,'\0',100);
		memset(base,'\0',100);
	    scanf("%s",s);
	    len=strlen(s);
	    count=0;
	    flag=0;
		for(j=0;j<len;j++)
		if(s[j]=='#')
		 count++;
		 if(count==0) {
			 for(j=0;j<len;j++)
			 if(test(10,s[j])!=1){
               flag=1;
               break;
			 }
			 if(flag==1) {
				 printf("no\n");
				 continue;
				 }
			else {
				printf("yes\n");
				continue;
				}
			 }	    
			if(count>0){
			if(s[len-1]!='#'||(s[len-1]=='#'&&s[len-2]=='#')) {
			printf("no\n");
			flag=1;
            continue;
            }
			 } 
		if(count%2!=0)
		 {
			printf("no\n");
			continue; 
			 } 
		strcpy(ss,s);
		for(i=0;i<len;i++){
            if(ss[i]=='#') {
				ss[i]='0';
				break;
				}
			}
		for(i=len-1;i>-1;i--){
            if(ss[i]=='#') {
				ss[i]='0';
				break;
				}			
			}
		for(i=0;i<len;i++){
			if(ss[i]=='#'){
				if(ss[++i]!='#') {
					printf("no\n");
					flag=1;
					break;
					}
				}
			}	
	    for(i=0;i<len;i++){
			if(s[i]=='#') break;
			base[i]=s[i];
			if(base[i]>'9'||base[i]<'0') flag=1;
			}
		if(flag==1) {
			printf("no\n");
			continue;
			}
		b=atoi(base);
		if(b>16||b<2) {
			printf("no\n");
			continue;
			}



		count=0;

			
			
		count=0;
		for(;i<len;i++){
			if(flag==1) break;
            if(s[i]!='#'&&test(b,s[i])==0) {
				printf("no\n");
				flag=1;
				break;
				}
			if(s[i]=='#') {
			count++;
			if(count%2==0&&count!=0)
			b=change(b,i+1);
			if((b>16)&&s[i+1]!='\0') {
				flag=1;
				printf("no\n");
				break;
				}
				continue;
				}



			}
		if(flag==0) printf("yes\n");
		
		
	    
	    
	    
    }
	
	
	
	return 0;
	}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator