深爱那片海 发表于 2015-1-18 11:19:00

来看java完成阴阳历算法

你通过从书的数量和开发周期及运行速度来证明:net网页编程和ruby要比java简单。
程序为:
/*
西历夏历转换程式黄晓叫1995,7,25
prototype:intcalconv(structconvdate*);
structconvdate
{
intsource;==0则输出日期为西历,!=0则输出为夏历
intsolaryear;输入或输出之西积年份
intsolarmonth;西历月
intsolardate;西历日
intlunaryear;输入或输出之夏历年份
intlunarmonth;夏历月
intlunardate;夏历日
intweekday;该日为礼拜几(0==日曜日,1==礼拜一,...)
intkan;该日天干(0==甲,1==乙,...,9==癸)
intchih;该日地支(0==子,1==丑,...,11==亥)
};
呼唤时须设定souce的值,若为0则为西历转夏历,不然为夏历转西历.然後视
输出为西历或夏历来设定西历或夏历的年代日.转换後的年代日会填进布局中(农
历或西历),和该日为礼拜几,天干地支.
若函式的前往值为0暗示没有毛病,1为输出之年份毛病,2为输出之月份毛病,
3为输出之日期毛病.
输出之西积年须在1937-2031间
输出之夏历年须在1936-2030间
若须扩大,则增添lunarcal[]
*/
#definefirstyear1936/*thefirstyearinlunarcal[]*/
structconvdate
{
intsource;
intsolaryear;
intsolarmonth;
intsolardate;
intlunaryear;
intlunarmonth;
intlunardate;
intweekday;
intkan;
intchih;
};
structtaglunarcal
{
intbasedays;/*到西历1月1日到夏历正月月朔的积累日数*/
intintercalation;/*闰月月份.0==此年没有闰月*/
intbaseweekday;/*此年西历1月1日为礼拜几再减1*/
intbasekanchih;/*此年西历1月1日之干支序号减1*/
intmonthdays;/*此夏历年每个月之巨细,0==小月(29日),1==年夜月(30日)*/
};
structtaglunarcallunarcal[]={
{23,3,2,17,1,0,0,1,0,0,1,1,0,1,1,1,0},/*1936*/
{41,0,4,23,1,0,0,1,0,0,1,0,1,1,1,0,1},
{30,7,5,28,1,1,0,0,1,0,0,1,0,1,1,0,1},
{49,0,6,33,1,1,0,0,1,0,0,1,0,1,0,1,1},
{38,0,0,38,1,1,0,1,0,1,0,0,1,0,1,0,1},/*1940*/
{26,6,2,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54,0,1,0,1,0,1,0,1,1,0,1,0,1},
{40,0,0,59,0,1,0,0,1,0,1,1,0,1,1,0,1},/*2024*/
{28,6,2,5,1,0,1,0,0,1,0,1,0,1,1,1,0},
{47,0,3,10,1,0,1,0,0,1,0,0,1,1,1,0,1},
{36,0,4,15,1,1,0,1,0,0,1,0,0,1,1,0,1},
{25,5,5,20,1,1,1,0,1,0,0,1,0,0,1,1,0},/*2028*/
{43,0,0,26,1,1,0,1,0,1,0,1,0,0,1,0,1},
{32,0,1,31,1,1,0,1,1,0,1,0,1,0,1,0,0},
{22,3,2,36,0,1,1,0,1,0,1,1,0,1,0,1,0}};
#definelastyear(firstyear+sizeof(lunarcal)/sizeof(structtaglunarcal)-1)
/*西积年每个月之日数*/
intsolarcal={31,28,31,30,31,30,31,31,30,31,30,31};
/*西积年每个月之积累日数,闰年与闰年*/
intsolardays={
{0,31,59,90,120,151,181,212,243,273,304,334,365,396},
{0,31,60,91,121,152,182,213,244,274,305,335,366,397}};
/*求此西积年是不是为闰年,前往0为闰年,1为闰年*/
intgetleap(intyear)
{
if(year%400==0)
return1;
elseif(year%100==0)
return0;
elseif(year%4==0)
return1;
else
return0;
}
/*西历夏历转换*/
intcalconv(structconvdate*cd)
{
intleap,d,sm,y,im,l1,l2,acc,i,lm,kc;
if(cd->source==0)/*solar*/
{
if(cd->solaryear<=firstyear||cd->solaryear>lastyear)
return1;
sm=cd->solarmonth-1;
if(sm<0||sm>11)
return2;
leap=getleap(cd->solaryear);
if(sm==1)
d=leap+28;
else
d=solarcal;
if(cd->solardate<1||cd->solardate>d)
return3;
y=cd->solaryear-firstyear;
acc=solardays+cd->solardate;
cd->weekday=(acc+lunarcal.baseweekday)%7;
kc=acc+lunarcal.basekanchih;
cd->kan=kc%10;
cd->chih=kc%12;
if(acc<=lunarcal.basedays)
{
y--;
cd->lunaryear=cd->solaryear-1;
leap=getleap(cd->lunaryear);
sm+=12;
acc=solardays+cd->solardate;
}
else
cd->lunaryear=cd->solaryear;
l1=lunarcal.basedays;
for(i=0;i<13;i++)
{
l2=l1+lunarcal.monthdays+29;
if(acc<=l2)
break;
l1=l2;
}
cd->lunarmonth=i+1;
cd->lunardate=acc-l1;
im=lunarcal.intercalation;
if(im!=0&&cd->lunarmonth>im)
{
cd->lunarmonth--;
if(cd->lunarmonth==im)
cd->lunarmonth=-im;
}
if(cd->lunarmonth>12)
cd->lunarmonth-=12;
}
else/*lunar*/
{
if(cd->lunaryear<firstyear||cd->lunaryear>=lastyear)
return1;
y=cd->lunaryear-firstyear;
im=lunarcal.intercalation;
lm=cd->lunarmonth;
if(lm<0)
{
if(lm!=-im)
return2;
}
elseif(lm<1||lm>12)
return2;
if(im!=0)
{
if(lm>im)
lm++;
elseif(lm==-im)
lm=im+1;
}
lm--;
if(cd->lunardate>lunarcal.monthdays+29)
return3;
acc=lunarcal.basedays;
for(i=0;iacc+=lunarcal.monthdays+29;
acc+=cd->lunardate;
leap=getleap(cd->lunaryear);
for(i=13;i>=0;i--)
if(acc>solardays)
break;
cd->solardate=acc-solardays;
if(i<=11)
{
cd->solaryear=cd->lunaryear;
cd->solarmonth=i+1;
}
else
{
cd->solaryear=cd->lunaryear+1;
cd->solarmonth=i-11;
}
leap=getleap(cd->solaryear);
y=cd->solaryear-firstyear;
acc=solardays+cd->solardate;
cd->weekday=(acc+lunarcal.baseweekday)%7;
kc=acc+lunarcal.basekanchih;
cd->kan=kc%10;
cd->chih=kc%12;
}
return0;
}

JAVA学习必须明确这是一项投资,对于大多数的人来说,学习JAVA是为了就业,还有就是刚走向工作位置的朋友想尽快赶上工作的节奏。

只想知道 发表于 2015-1-18 22:50:38

是一种将安全性(Security)列为第一优先考虑的语言

海妖 发表于 2015-1-21 13:20:35

你快去找一份Java的编程工作来做吧(如果是在校学生可以去做兼职啊),在实践中提高自己,那才是最快的。不过你得祈祷在公司里碰到一个高手,而且他 还愿意不厌其烦地教你,这样好象有点难哦!还有一个办法就是读开放源码的程序了。我们知道开放源码大都出自高手,他们设计合理,考虑周到,再加上有广大的程序员参与,代码的价值自然是字字珠叽,铿锵有力(对不起,偶最近《金装四大才子》看多了)。

山那边是海 发表于 2015-1-24 15:10:31

Java自面世后就非常流行,发展迅速,对C++语言形成了有力冲击。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台

冷月葬花魂 发表于 2015-1-24 16:18:58

Java是一个纯的面向对象的程序设计语言,它继承了 C++语言面向对象技术的核心。Java舍弃了C ++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)

蒙在股里 发表于 2015-1-24 18:20:41

我大二,Java也只学了一年,觉得还是看thinking in java好,有能力的话看英文原版(中文版翻的不怎么好),还能提高英文文档阅读能力。

不帅 发表于 2015-2-4 20:57:50

是一种由美国SUN计算机公司(Sun Microsystems, Inc.)所研究而成的语言

再见西城 发表于 2015-2-10 09:31:18

让你能够真正掌握接口或抽象类的应用,从而在原来的Java语言基础上跃进一步,更重要的是,设计模式反复向你强调一个宗旨:要让你的程序尽可能的可重用。

简单生活 发表于 2015-2-25 12:37:54

如果要向java web方向发展也要吧看看《Java web从入门到精通》学完再到《Struts2.0入门到精通》这样你差不多就把代码给学完了。有兴趣可以看一些设计模块和框架的包等等。

柔情似水 发表于 2015-3-7 20:27:15

科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。

小魔女 发表于 2015-3-15 13:05:57

是一种使网页(Web Page)产生生动活泼画面的语言

再现理想 发表于 2015-3-22 01:09:29

那么我书也看了,程序也做了,别人问我的问题我都能解决了,是不是就成为高手了呢?当然没那么简单,这只是万里长征走完了第一步。不信?那你出去接一个项目,你知道怎么下手吗,你知道怎么设计吗,你知道怎么组织人员进行开发吗?你现在脑子里除了一些散乱的代码之外,可能再没有别的东西了吧!

仓酷云 发表于 2015-3-22 01:09:30

是一种由美国SUN计算机公司(Sun Microsystems, Inc.)所研究而成的语言

飘灵儿 发表于 2015-3-22 01:09:30

一般学编程语言都是从C语开始学的,我也不例外,但还是可能不学过程语言而直接学面向对象语言的,你是刚接触语言,还是从C开始学比较好,基础会很深点,如果你直接学习JAVA也能上手,一般大家在学语言的时候都记一些语言的关键词,常有的包和接口等。再去做逻辑代码的编写,以后的学习过程都是从逻辑代码编写中提升的,所以这方面都是经验积累的。你要开始学习就从

因胸联盟 发表于 2015-3-22 01:09:31

是一种为 Internet发展的计算机语言
页: [1]
查看完整版本: 来看java完成阴阳历算法