標題:
==生命靈數==
[打印本頁]
作者:
p17johnny
時間:
2011-11-12 19:58
標題:
==生命靈數==
本帖最後由 p17johnny 於 2011-11-12 20:04 編輯
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
fstream fin,fout;
fin.open("pf.in",ios::in);
fout.open("pf.out",ios::out);
int ymd;
int t;
fin >> t;
int a=0,b=0,d=0,c=0;
for(int i=1;i<=8;i++)
{
a=ymd%10+a;
c=ymd%10+a;
ymd=ymd/10;
}
if(t>=10)
{
d=t/10;
b=t%10;
t=d+b;
d=0 ;
b = 0 ;
}
if(t>=10)
{
d=t/10 ;
b=t%10 ;
t=d+c;
}
if(t==2)
{
fout<< t << ", Yes"<< endl ;
}else
{
fout<< t << ", No" << endl ;
}
fin.close();
fout.close();
return 0;
}
複製代碼
求解其他人的解題方法
作者:
chuangjoy
時間:
2011-11-12 20:58
#include <iostream>
#include <fstream>
using namespace std;
int main(void){
fstream fin, fout;
fin.open("pf.in",ios::in);
fout.open("pf.out",ios::out);
int n, x;
int a, b, c, d, e, f, g;
fin >> n;
for(int i=0; i<=n; i++){
fin >> x;
while(x>=10){
a = x/10000000;
x = x%10000000;
b = x/1000000;
x = x%1000000;
c = x/100000;
x = x%100000;
d = x/10000;
x = x%10000;
e = x/1000;
x = x%1000;
f = x/100;
x = x%100;
g = x/10;
x = x%10;
x = a+b+c+d+e+f+g+x;
}
fout << x <<", ";
if(x==2){
fout <<"Yes"<< endl;
}else{
fout <<"No"<< endl;
}
}
fin.close();
fout.close();
}
複製代碼
超級爛方法 @@
作者:
ray
時間:
2011-11-30 17:54
/**********************************************************************************/
/* 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;
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2