返回列表 發帖

==生命靈數==

本帖最後由 p17johnny 於 2011-11-12 20:04 編輯
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int main()
  5. {
  6.     fstream fin,fout;
  7.         fin.open("pf.in",ios::in);
  8.         fout.open("pf.out",ios::out);
  9.         int ymd;
  10.         int t;
  11.         fin >> t;
  12.         int a=0,b=0,d=0,c=0;
  13.         for(int i=1;i<=8;i++)
  14.         {
  15.         a=ymd%10+a;
  16.         c=ymd%10+a;
  17.         ymd=ymd/10;
  18.         }
  19.     if(t>=10)
  20.             {
  21.             d=t/10;
  22.             b=t%10;
  23.             t=d+b;
  24.             d=0 ;
  25.             b = 0 ;
  26.             }
  27.             if(t>=10)
  28.             {
  29.             d=t/10 ;
  30.             b=t%10 ;
  31.             t=d+c;
  32.             }
  33.         if(t==2)
  34.         {
  35.         fout<< t << ", Yes"<< endl ;
  36.         }else
  37.         {
  38.         fout<< t << ", No" << endl ;
  39.         }
  40.        
  41.        
  42.         fin.close();
  43.         fout.close();
  44.        
  45.         return 0;
  46.         }
複製代碼
求解其他人的解題方法
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊
分數掛蛋的心情像空白的紙,再次期望著奇蹟的到來。

  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int main(void){
  5.    
  6.     fstream fin, fout;
  7.     fin.open("pf.in",ios::in);
  8.     fout.open("pf.out",ios::out);
  9.    
  10.     int n, x;
  11.     int a, b, c, d, e, f, g;
  12.     fin >> n;
  13.     for(int i=0; i<=n; i++){
  14.             fin >> x;
  15.    
  16.             while(x>=10){
  17.                  a = x/10000000;
  18.                  x = x%10000000;
  19.                  b = x/1000000;
  20.                  x = x%1000000;
  21.                  c = x/100000;
  22.                  x = x%100000;
  23.                  d = x/10000;
  24.                  x = x%10000;
  25.                  e = x/1000;
  26.                  x = x%1000;
  27.                  f = x/100;
  28.                  x = x%100;
  29.                  g = x/10;
  30.                  x = x%10;
  31.                  x = a+b+c+d+e+f+g+x;
  32.             }
  33.                  fout << x <<", ";
  34.             if(x==2){
  35.                  fout <<"Yes"<< endl;
  36.                  }else{
  37.                  fout <<"No"<< endl;
  38.             }
  39.     }
  40.    
  41.    
  42.     fin.close();
  43.     fout.close();
  44. }
複製代碼
超級爛方法 @@

TOP

/**********************************************************************************/
/*  Problem: d593 "F. 生命靈數" from 2009 NPSC 國中組初賽                */
/*  Language: CPP (483 Bytes)                                                     */
/*  Result: AC(4ms, 384KB) judge by this@ZeroJudge                                */
/*  Author: ray0410 at 2011-11-12 23:35:34                                        */
/**********************************************************************************/


#include<iostream>
using namespace std;

int main()
{
    int magic,number,total;
    cin >> total;
    while(total>0)
    {
      cin >> number;
      do
      {
         magic = 0;
         while(number>0)
         {
           magic += number % 10;
           number = number / 10;
         }
         number = magic;
      }
      while(magic > 9);
      cout << magic << ", " << (magic==2?"Yes":"No") << endl;
      total--;
    }

    return 0;
}

TOP

返回列表