ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

刷题笔记day11

2020-04-19 23:57:18  阅读:222  来源: 互联网

标签:pnum int 笔记 ++ num day11 pair include 刷题


报数

#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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有