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

你程序有问题,而用vc的时候碰巧过了而已

Posted by hawk at 2004-05-02 22:00:55 on Problem 1519
In Reply To:为什么这个程序用GCC不过,而C++就过了呢???? Posted by:Grope at 2004-05-02 21:32:45
你的number不够长,你改长一点就可以用gcc过了
当然,这种题目没告诉你长度的
就是暗示你可以不用数组来存的
你的做法是不好的
> #include<iostream>
> using namespace std;
> char number[1000];
> int root,i,temp;
> int main()
> {
>     while(cin>>number&&number[0]!='0'){
>         root=0;
>         for(i=0;number[i];i++)
>              root+=number[i]-'0';
>         while(root>9){
>             temp=root;
>             root=0;
>             while(temp)
>                 root+=temp%10,temp/=10;
>         }
>         cout<<root<<endl;
>     }
>     return 1;
> }

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