| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
你程序有问题,而用vc的时候碰巧过了而已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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator