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

50A~ 贴下代码

Posted by a553865290 at 2012-04-03 00:29:59 on Problem 1426
#include<iostream>
#include<queue>
using namespace std;
int main()
{
    __int64 temp,te;
    int n,tt;
    bool flag[204];
    while(cin>>n && n!=0){
          memset(flag,false,sizeof(flag));
          queue<__int64> q;
          q.push(1);
          while(!q.empty()){
                  temp=q.front();
                  q.pop();
                  if(temp%n==0){cout<<temp<<endl; break;}
                  else{
                       for(int i=0;i<2;i++){
                           tt=(temp*10+i)%n; 
                           if(!flag[tt]){
                              flag[tt]=true;
                              te=temp*10+i;
                              q.push(te); 
                              if(te%n==0)break;
                           }
                       }
                       if(te%n==0){cout<<te<<endl;break;}
                  }          
          }     
    }
    return 0;
}

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