其他分享
首页 > 其他分享> > 刷题笔记day11

刷题笔记day11

作者:互联网

报数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int a[]={0,0,0,0};
int is7(int n)
{
    if(n%7==0)return 1;

    char str[30];
    sprintf(str,"%d",n);
    //printf("%s\n",str);
    int len = strlen(str);
    int i;
    for(i=0;i<len;i++)
    {
        if(str[i] == '7')
            return 1;
    }

    return 0;
}
int main()
{
    int n;
    scanf("%d",&n);
    int i=1;
    int d=1;
    while(i<=n)
    {
        if(is7(d))
        {
            //printf("%d\n",d);
            a[(d-1)%4]++;
            d++;
        }
        else
        {
            i++;
            d++;
        }
    }
    for(i=0;i<4;i++)
        printf("%d\n",a[i]);
    return 0;
}

 垃圾回收站评分

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<map>
#include<vector>
using namespace std;
int num[]={0,0,0,0,0};
vector<pair<int,int>> l;
int isfind(pair<int,int> p)
{
    //cout<<"1111"<<endl;
    vector<pair<int,int>>::iterator it;
    for(it = l.begin();it!=l.end();++it)
    {
        //cout<<"222"<<endl;
        //cout<<(*it).first<<(*it).second<<endl;
        if((*it).first == p.first
           && (*it).second == p.second)
        {
            //cout<<"33333"<<endl;
            return 1;
        }
    }
    //cout<<"44444"<<endl;
    return 0;
}
int main()
{
    int n;
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        int tempx;
        int tempy;
        scanf("%d%d",&tempx,&tempy);
        pair<int,int> tempp =make_pair(tempx,tempy);
        l.push_back(tempp);
    }

    vector<pair<int,int>>::iterator it;
    for(it=l.begin();it!=l.end();it++)
    {
        int xx = (*it).first;
        int yy = (*it).second;
        pair<int,int> p1 = make_pair(xx+1,yy);
        pair<int,int> p2 = make_pair(xx-1,yy);
        pair<int,int> p3 = make_pair(xx,yy+1);
        pair<int,int> p4 = make_pair(xx,yy-1);
        pair<int,int> p5 = make_pair(xx+1,yy+1);
        pair<int,int> p6 = make_pair(xx-1,yy+1);
        pair<int,int> p7 = make_pair(xx+1,yy-1);
        pair<int,int> p8 = make_pair(xx-1,yy-1);

        if(isfind(p1)&&isfind(p2)&&isfind(p3)&&isfind(p4))
        {
            int score = 0;
            if(isfind(p5)) score++;
            if(isfind(p6)) score++;
            if(isfind(p7)) score++;
            if(isfind(p8)) score++;
            num[score]++;
        }


    }
    for(int j=0;j<5;j++)
        printf("%d\n",num[j]);

}

小明疏果

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<string.h>
#include<malloc.h>
int jian[1005];
int main()
{
    memset(jian,0,sizeof(jian));
    int n,m;
    scanf("%d%d",&n,&m);
    int i,j;
    int sum=0;
    for(i=0;i<n;i++)
    {
        int tempnum;
        scanf("%d",&tempnum);
        sum += tempnum;
        for(j=0;j<m;j++)
        {
            int x;
            scanf("%d",&x);
            jian[i] -= x;
            sum += x;
        }
    }

    int k;
    int maxjian = -1;
    for(j=0;j<m;j++)
    {
        if(jian[j]>maxjian)
        {
            k=j;
            maxjian=jian[j];
        }
    }

    printf("%lld %d %d\n",sum,k+1,jian[k]);
}

疏果2

 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int isshu[1005];
int main()
{
    memset(isshu,0,sizeof(isshu));
    int n;
    scanf("%d",&n);
    int sum = 0;//苹果总数
    int numtree = 0;//棵树
    int numsan = 0;
    int i;
    for(i=0;i<n;i++)
    {
        int m;
        scanf("%d",&m);
        int j;
        int numtree1 = -1;
        for(j=0;j<m;j++)
        {
            int x;
            scanf("%d",&x);
            if(x>0)
            {
                if(x<numtree1)
                {
                    isshu[i] = 1;
                }
                numtree1 = x;

            }
            else
            {
                numtree1 += x;
            }
        }
        sum += numtree1;
    }

    for(i=0;i<n;i++)
    {
        numtree += isshu[i];
    }

    i=0;
    while(i<n)
    {
        if(isshu[i]&&isshu[(i+1)%n]
           &&isshu[(i+2)%n])
            numsan++;
        i++;
    }

    printf("%d %d %d\n",sum,numtree,numsan);
}

中小大

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
double a[100005];
int cmp(double a,double b)
{
    return a-b;
}
int main()
{
    int n;
    scanf("%d",&n);
    if(n == 0 )return 0;

    int i;
    for(i=0;i<n;i++)
    {
        scanf("%lf",&a[i]);
    }


    sort(a,a+n);

    if(n%2 ==1)
    {
        double b[] = {a[0],a[n-1],a[n/2]};
        sort(b,b+3);
        printf("%.0f %.0f %.0f\n",b[2],b[1],b[0]);
    }
    else
    {
        if((int)(a[n/2-1]+a[n/2])%2==0)
        {

            double b[] = {a[0],a[n-1],(a[n/2]+a[n/2-1])/2};
            //printf("%.0f %.0f %.0f\n",b[2],b[1],b[0]);
            sort(b,b+3);
            printf("%.0f %.0f %.0f\n",b[2],b[1],b[0]);
        }
        else
        {
            double b[] = {a[0],a[n-1],(a[n/2]+a[n/2-1])/2};
            sort(b,b+3);
            printf("%.0f %.1f %.0f\n",b[2],b[1],b[0]);
        }
    }


}

24点

#include<stdio.h>
#include<string.h>
int num[20];
char op[20];
int pnum=0;
int pop=0;
int main()
{
    int n;
    scanf("%d",&n);

    int i;
    for(i=0;i<n;i++)
    {
        pnum=pop=0;
        int chenggong = 1;
        char str[20];
        scanf("%s",str);
        int len = strlen(str);
        int j;
        for(j=0;j<len;j++)
        {
            char tempc = str[j];
            if(tempc>='0'&&tempc<='9')
            {
                num[pnum++] = (tempc-'0');
            }
            else if(tempc=='x'||tempc=='/')
            {
                int tempx = num[pnum-1];
                pnum--;
                j++;
                int tempy = (str[j]-'0');

                if(tempc == 'x')
                {
                    num[pnum++] = tempx*tempy;
                }
                else if(tempc == '/')
                {
                    if(tempx%tempy!=0)chenggong = 0;
                    num[pnum++] = tempx/tempy;
                }

            }
            else if(tempc=='+'||tempc=='-')
            {
                while(pop>0)
                {
                    char tempop = op[pop-1];
                    pop--;

                    int tempy = num[pnum-1];
                    pnum--;

                    int tempx = num[pnum-1];
                    pnum--;

                    if(tempop=='+')
                    {
                        num[pnum++] = tempx+tempy;
                    }
                    else
                    {
                        num[pnum++] = tempx-tempy;
                    }
                    //printf("%d\n",num[pnum-1]);
                }

                op[pop++] = tempc;
            }
        }

        while(pop>0)
        {
            char tempop = op[pop-1];
            pop--;

            int tempy = num[pnum-1];
            pnum--;

            int tempx = num[pnum-1];
            pnum--;

            if(tempop=='+')
            {
                num[pnum++] = tempx+tempy;
            }
            else
            {
                num[pnum++] = tempx-tempy;
            }
            //printf("%d\n",num[pnum-1]);
        }


        //printf("%d\n",num[0]);
        if(num[0]==24)
            printf("Yes\n");
        else printf("No\n");
    }
}

标签:pnum,int,笔记,++,num,day11,pair,include,刷题
来源: https://www.cnblogs.com/yoyoyayababy/p/12735117.html