回文日:发现日期合格判断还是贺老师给的屌一些,通过switch()的方式很有意思,也很简便,一些格式也很棒,学习了,
----------------------------------
寻找完全数:试了试找第五个完全数(33550336),额,等得我花儿都谢了。闲来无事,百度了一下完全数,发现完全数满足”三角型数“这个特性,要是可以用这个来找就方便了...>其他的特性不知道怎么用<
回:
#include <iostream>
using namespace std;
const int days[] = {0,31,0,31,30,31,30,31,31,30,31,30,31};
int palindromeCheck(int year)
{
char syear[5];
int month,day;
itoa(year,syear,10);
month = (syear[3]-48)* 10 + syear[2]-48;
day = (syear[1]-48) * 10 + syear[0]-48;
if (month <= 12)
{
if (month == 2)
{
if ( (year%4==0 && year%100!=0) || year%400==0)
{
if (day > 29) return 0;
}else{
if (day > 28) return 0;
}
}
else if (days[month] < day )
return 0;
return 1;
}
return 0;
}
void main()
{
int nCount = 0;
for (int i = 1 ; i <= 80; i ++)
{
if (palindromeCheck(i + 2012)==1){
nCount ++;
cout<<i+2012<<endl;
}
}
cout<<nCount<<endl;
}
完全数 :
#include <iostream>
#include <math.h>
using namespace std;
void main()
{
int i,j;
for (i = 2; i<=100000000; i++)
{
int s=1;
for (j = 2; j<sqrt(i); j++)
{
if (i%j == 0 ){
s += j + i/j;
}
}
if (i%j==0 && j!=i/j)
s+= j+j/j;
if (s == i) cout<<i<<endl;
}
}