码迷,mamicode.com
首页 > 其他好文 > 详细

计算任意两天之间的天数

时间:2018-09-02 20:22:34      阅读:872      评论:0      收藏:0      [点我收藏+]

标签:def   i++   ret   div   names   std   using   cin   span   

site:http://bailian.openjudge.cn/xly2018/

1、计算任意两天之间的天数

思路:以0为起始点计算天数,然后相减即可。这样的编码复杂度会减少很多。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isleapyear(int y){
    return (y%4==0&&y%100!=0||y%400==0);
}
int sum1(int a1,int b1,int c1){
    int md[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int res=a1*365;
    res+=(a1-1)/4+1;
    res-=(a1-1)/100+1;
    res+=(a1-1)/400+1;
    for(int i=1;i<b1;i++)res+=md[i];
    if(b1>2&&isleapyear(a1)) res++;
    res+=c1;
    return res;
}
int cnt(int a1,int b1,int c1,int a2,int b2,int c2){
    int res1=sum1(a1,b1,c1);
    int res2=sum1(a2,b2,c2);
    int ans=res2-res1;
    return ans;
}
int main(){
    int a1,b1,c1,a2,b2,c2;
    cin>>a1>>b1>>c1>>a2>>b2>>c2;
    printf("%d\n",cnt(a1,b1,c1,a2,b2,c2));
    return 0;
}

 2、回文子串

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        int res=1;
        int residx=0;
        int length=0;
        for(int i=0;i<s.size();i++){
            int j=1;
            for(;;j++){
                if(i-j<0||i+j>=s.size()) break;
                if(s[i-j]!=s[i+j]) break;
            }
            j--;
            if(2*j+1>res){
                res=2*j+1;
                residx=i;
                length=j;
            }
        }
        for(int i=residx-length;i<=residx+length;i++){
            printf("%c",s[i]);
        }
        printf("\n");
    }
}

3、

计算任意两天之间的天数

标签:def   i++   ret   div   names   std   using   cin   span   

原文地址:https://www.cnblogs.com/elpsycongroo/p/9574539.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!