#1497: 頭大的WA,不知道問題在哪


timmymike (超小小蝦米)


# include <iostream>


using namespace std ;


int CaCuDigit( int num ) {
// 計算輸入的數有幾位
  int digit = 1 ;
  for( ; num >= 10 ; digit ++  )
    num /= 10 ; 
  return digit ;
 
} // CaCuDigit


bool IsArmNum( int num ) {
// 如果是阿姆斯壯數,回傳true
  int digit = CaCuDigit( num ) ;
  int cacu = num ; // 計算中將用到的數字
  int nowcacu = 0 ; // 現在正要計算的次方數
  int total = 0 ; // 次方後加起來的值 
  int totalsqr = 1 ; // 次方後的值

  for ( int i = digit ; i > 0 ; i -- ) { // 所有數字和的迴圈
       
    nowcacu = cacu % 10 ;
    cacu /= 10 ;
    totalsqr = 1 ;
    for ( int j = digit ; j > 0 ; j -- ) { //  個別數字次方的迴圈
      totalsqr *= nowcacu ;
    } // for

    total += totalsqr ;

  } // for

  if ( total == num )
    return true ;
  else
    return false ;

} // IsArmNum

int main() {
 
  int smalln = 0, bigm = 0 ;
  bool none = true ;

  while ( cin >> smalln >> bigm  ) {

       
    for ( int i = smalln ; i <= bigm ; i ++ ) {
      if ( IsArmNum( i ) ) {
        cout << i << " " ;
        none = false ;
      } // if
    } // for

    if ( none )
      cout << "none" << endl ;
    else
      cout << endl ;

  } // while
 

  return 0  ;


} // main()

/*

在家用DevC測1-1000000都是沒問題的,為什麼一上來測就會WA還是"none"....

有沒有人可以幫我找出這個bug...誠摯的感謝再感謝


*/

 

#4639: Re:頭大的WA,不知道問題在哪


asdf80730 (任風吹乾)


大大你好,我用你的程式碼並且用DEV C++

輸入10 99沒有結果跑出來

100 999出來的結果是正常的

所以加油吧~~