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:POJ 1001,我的代码自己编译输出结果时正确的啊,为什么是WA?大家帮看看?C++的

Posted by netor at 2010-07-08 20:39:38
In Reply To:POJ 1001,我的代码自己编译输出结果时正确的啊,为什么是WA?大家帮看看?C++的 Posted by:chdl21cn at 2010-05-13 17:59:06
> #include <iostream>
> #include <stdlib.h>
> #include   <stdio.h>
> #include   <string.h>
> using namespace std;
> 
> int main()
> {
>     int n,i,j,k,d,len,x,jin;
>     string s,f,s1,s2,z,cj;
>     char c[1000],tmp,t1,t2;
>     while(cin>>c>>n)
>     {
>         s=c;
>         d=s.find(".");
>         len=s.length();
>         s1=s;
>         if(d!=string::npos)
>             s1.erase(d,1);
>         strcpy(c,s1.c_str());
>         for(int i=0,j=strlen(c)-1;i<j;i++,j--)
>         {
>             tmp=c[i];
>             c[i]=c[j];
>             c[j]=tmp;
>         }
>         s1=c;
>         s2=s1;
>         for(i=1;i<n;i++)
>         {
>             z.clear();
>             cj.clear();
>             for(j=0;j<s2.length();j++)
>             {
>                 jin=0;
>                 f.clear();
>                 for(k=0;k<s1.length();k++)
>                 {
>                     x=atoi(s2.substr(j,1).c_str())*atoi(s1.substr(k,1).c_str())+jin;
>                     sprintf(c,"%d",x%10);
>                     f.append(c);
>                     jin=x/10;
>                 }
>                 if(jin>0)
>                 {
>                     sprintf(c,"%d",jin);
>                     f.append(c);
>                 }
>                 f.insert(0,z);
>                 z.append("0");
>                 jin=0;
>                 for(k=0;k<f.length();k++)
>                 {
>                     if(k<cj.length())
>                     {
>                         x=atoi(f.substr(k,1).c_str())+atoi(cj.substr(k,1).c_str())+jin;
>                         sprintf(c,"%d",x%10);
>                         cj.replace(k,1,c);
>                         jin=x/10;
>                     }
>                     else
>                     {
>                         x=atoi(f.substr(k,1).c_str())+jin;
>                         sprintf(c,"%d",x%10);
>                         cj.append(c);
>                         jin=x/10;
>                     }
>                 }
>                 if(jin>0)
>                 {
>                     sprintf(c,"%d",jin);
>                     cj.append(c);
>                 }
>             }
>             s1=cj;
>         }
>         if(d!=string::npos)
>         {
>             d=len-d-1;
>             if(d>0)
>             {
>                     s1.insert(d*n,".");
>             }
>         }
>         strcpy(c,s1.c_str());
>         for(int i=0,j=strlen(c)-1;i<j;i++,j--)
>         {
>             tmp=c[i];
>             c[i]=c[j];
>             c[j]=tmp;
>         }
>         s1=c;
>         t1='0';
>         t2='.';
>         while(*s1.substr(0,1).c_str()==t1)
>         {
>             s1.erase(0,1);
>         }
> 
>         if(d>0)
>         {
>             while(*s1.substr(s1.length()-1,1).c_str()==t1||*s1.substr(s1.length()-1,1).c_str()==t2)
>             {
>                 s1.erase(s1.length()-1,1);
>             }
>         }
>         strcpy(c,s1.c_str());
>         cout<<c<<endl;
>     }
>     system("Pause");
>     return 0;
> }
> 
> 我无论如何输入,自己运行的结果都是正确的,和计算器出来的一样,但是提交后就是WA,郁闷死了。
> 而我从网上找了一段C的自己验证有时计算结果是错误的,用来提交后居然AC,.. 我真是无语啊。。
> 我的代码怎么就WA了?请高手帮忙看看

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