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:你的输入有一点问题,只能输入一次,要是用while(cin>>i>>j)应该就行了^^^^

Posted by ggshen_1986 at 2009-03-14 10:52:11 on Problem 1207
In Reply To:陷阱我避免了阿 数据测试都对的 poj是不是有问题阿 Posted by:strideryu at 2009-03-07 17:22:47
> 代码贴上:
> #include<iostream>
> using namespace std;
> int cycle_length(int k);
> int main()
> {
>     int i,j,k,temi,temj,tem,answer;
>     cin>>i>>j;
>     if(i>j){
>             temj=i;
>             temi=j;
>             }
>     else {
>          temj=j;
>          temi=i;
>          }
>     //用temi,temj来计算,temi<=temj
>     for(k=temi;k<=temj;k++){
>        if(k==temi)answer=cycle_length(k); 
>        else {
>             tem=cycle_length(k);
>             if(tem>answer)answer=tem;
>             }
>        }
>     cout<<i<<" "<<j<<" "<<answer;
>     return 0;  
> }
> //--------------------------------------------------
> int cycle_length(int k)
> {
> int c_l=1;
> while(k!=1){
>    if(k%2==0)
>        k/=2;
>    else 
>        k=(3*k+1);
>    c_l++;
>    }
> return c_l;
> }

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