# 算法设计问题，小白一个求大神带飞

0

3

2000-4-5

2001-5-4

2010-10-24

96

124

297

0

int[] day4m=[31,28,31,30,31,30,31,31,30,31,30,31]

function int day4ym(int year,int m){if(m==2){判断闰年返回day4m[m-1]+1}else{return day4m[m-1];}}

@遥路漫漫:

``` function day4year( y, m, d ) {
var day4m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if ( y < 0 || m < 0 || d < 0 ) {
return -1;
}
if ( m > 12 ) {
return -1;
}
if ( d > day4m[m] ) {
return -1;
}
var rt = d;
for ( var i = 0; i < m; i++ ) {
rt += day4m[i];
}
if ( isLeapYear( y ) && m > 2 ) {
rt += 1;
}
return rt;
}
function isLeapYear( y ) {
return ( ( ( y % 4 ) == 0 ) && ( y % 100 ) != 0 ) || ( y % 400 == 0 );
}```

@吴瑞祥: 大神能在帮个忙吗？

package mec.lanqiao; import java.util.*; public class Main {                static char[] upper = { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' }; // 大写数字                // 获取一个四位数的大写字符串，零的数目可以为多个               static String addZero(String t) {                               StringBuilder sb = new StringBuilder();                               int n1 = Integer.parseInt("" + t.charAt(0));                               int n2 = Integer.parseInt("" + t.charAt(1));                               int n3 = Integer.parseInt("" + t.charAt(2));                               int n4 = Integer.parseInt("" + t.charAt(3));                               if (n1 == 0) {                                              sb.append("零");                               } else {                                              sb.append(upper[n1] + "仟");                               }                               if (n2 == 0) {                                              sb.append("零");                               } else {                                              sb.append(upper[n2] + "佰");                               }                               if (n3 == 0) {                                              sb.append("零");                               } else {                                              sb.append(upper[n3] + "拾");                               }                               if (n4 != 0) {                                              sb.append(upper[n4]);                               }                               return sb.toString();               }                static void f(String num) {                               int len = num.length();                               if (len < 5) {                                              for (int i = 0; i < 4 - len; i++) {                                                             num = "0" + num;                                              }                                              String s = addZero(num);                                              // 去尾部的零                                              while (s.endsWith("零")) {                                                             s = s.substring(0, s.length() - 1);                                              }                                              // 去首部的零                                              while (s.startsWith("零")) {                                                             s = s.substring(1);                                              }                                              // 消除重复的零                                              s = s.replaceAll("零零零", "零");                                              s = s.replaceAll("零零", "零");                                              System.out.println(s);                               } else if (len < 9) {                                              String s, s1, s2;                                              s1 = num.substring(0, num.length() - 4);                                              int i = 4 - s1.length();                                              while (i-- > 0) {                                                             s1 = "0" + s1;                                              }                                              s1 = addZero(s1) + "万";                                              s2 = num.substring(num.length() - 4);                                              s2 = addZero(s2);                                              s = s1 + s2;                                              while (s.endsWith("零")) {                                                             s = s.substring(0, s.length() - 1);                                              }                                              while (s.startsWith("零")) {                                                             s = s.substring(1);                                              }                                              s = s.replaceAll("零零零", "零");                                              s = s.replaceAll("零零", "零");                                              System.out.println(s);                               } else {                                              String s, s1, s2, s3;                                              s1 = num.substring(0, num.length() - 8);                                              int i = 4 - s1.length();                                              while (i-- > 0) {                                                             s1 = "0" + s1;                                              }                                              s2 = num.substring(num.length() - 8, num.length() - 4);                                              s3 = num.substring(num.length() - 4);                                              s1 = addZero(s1) + "亿";                                              s2 = addZero(s2) + "万";                                              s3 = addZero(s3);                                              s = s1 + s2 + s3;                                              while (s.endsWith("零")) {                                                             s = s.substring(0, s.length() - 1);                                              }                                              while (s.startsWith("零")) {                                                             s = s.substring(1);                                              }                                              s = s.replaceAll("零零零", "零");                                              s = s.replaceAll("零零", "零");                                              System.out.println(s);                               }               }                public static void main(String[] args) {                               Scanner scan = new Scanner(System.in);                               String num = scan.next();                               scan.close();                               f(num);               }}

0

#include <conio.h>
#include<stdio.h>
void main()
{
int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i,j,k,y,m,d,b,n,sum;
int N=0;
int year[100];
int month[100];
int day[100];
scanf("%d",&N);
printf("日期输入格式：2010-6-9 \n");
for(i=0;i<N;i++)
scanf("%d-%d-%d",&year[i],&month[i],&day[i]);
for(j=0;j<N;j++)
{
sum=0;
for(i=1;i<month[j];i++)
sum=sum+days[i];
sum=sum+day[j];
if((year[j]%4==0||(year[j]%400==0&&year[j]%100!=0)) &&month[j]>2)
sum=sum+1;
printf("%d\n",sum);
}

getch();
}

您需要登录以后才能回答，未注册用户请先注册