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

Re:同在3725过了,这里WA 了

Posted by 110c at 2010-09-10 19:38:11 on Problem 2171
In Reply To:请教,这代码过了3725却在这WA了,不知道哪的问题 Posted by:200731000623 at 2009-09-18 03:04:36
#include <cstdlib>
#include <iostream>
using namespace std;
long long por(long long x)
{    
     long long y=1;    
     for(long long i=0;i<x;i++)    
     y*=10;    
     return y;
}
int main(int argc, char *argv[])
{  
    long long s;
    char m[30],k[30];  
    while(scanf("%s%s",m,k)!=-1)  
    {      
           long long im=0,ik=0,i;      
           long long lm=strlen(m),lk=strlen(k);      
           if(m[0]=='1')      
           {         
                     for(i=1;i<lm;i++)         
                     if(m[i]!='0') break;         
                     if(i==lm)         
                     {            
                                  if(k[0]==lm+'0') 
                                  printf("%I64d\n",por(lm-1));
                                  else printf("0\n");            
                                  continue;         
                     }       
           }      
           for(i=0;i<lm;i++)      
           im=im*10+m[i]-'0';      
           for(i=0;i<lk;i++)      
           ik=ik*10+k[i]-'0'; 
                      
           long long s=0,x=0;      
           for(i=0;i<lm;i++)      
           {x=x*10+m[i]-'0';s+=(x-por(i))+1;}      
           if(s>ik)       
           {printf("0\n");continue;}      
           else if(s==ik)       
           {printf("%I64d\n",im);continue;}  
           x=im-por(lm-1);      
           
           for(i=lm;s<ik;i++)      
           {         
                     x*=10;
                     s+=x;      
           }
            s-=x;x=ik-s-1;
            printf("%I64d\n",x+por(i-1));
    }             
    return EXIT_SUCCESS;
}

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