zoukankan      html  css  js  c++  java
  • 2019/02/02训练日记

    今天一个小时还是没有做出来一道自己想做出来的题,从51nod上把自己代码跑出的数据跟正确数据比对,发现一模一样,不知道为啥就是不给AC,很棘手。养足精神明天继续奋斗,因为耽误了这一个小时,今天只AC了六道题,今天回老家时间荒废在路上,希望明天可以更加努力。附上天没有通过的代码,明天一定雪耻。今天做题,终于碰了一些可以去思考的题,很久不用的size()跟sizeof()都快忘了,在巩固一下知识点。size是计算字符串字符数量,sizeof(int)是计算字节数常用于memset,memcpy。在这里插入图片描述

    我的答案
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<iomanip>
    #include <stdlib.h>
    using namespace std;
    int main()
    {
        int q[30]={0};
        long int a,b,i=0;
        int c=0;
        cin>>a>>b;
        while(a>0)
        {
            q[i]=a%b;
            a=a-q[i];
            a=a/b;
            i++;
        }
        for(int z=30;z>=0;z--)
        {
            if(q[z]!=0)
            {
                b=z;
                break;
            }
    
        }
        for(int z=b;z>=0;z--)
        {
            if(q[z]==10)cout<<'A';
            else if(q[z]==11) cout<<'B';
            else if(q[z]==12) cout<<'C';
            else if(q[z]==13) cout<<'D';
            else if(q[z]==14) cout<<'E';
            else if(q[z]==15) cout<<'F';
            else cout<<q[z];
        }
        cout<<endl;
        return 0;
    }
    正确答案
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int n,r,i;
        scanf("%d %d",&n,&r);
            if(n<0)
            {
                printf("-");n=-n;
            }
            if(n==0){printf("0
    ");}
            int c=0,a[100];
            while(n)
            {
                a[c]=(n%r);
                c++;
                n/=r;
            }
            for(i=c-1;i>=0;i--)
            {
                if(a[i]>=10)
                {
                    printf("%c",'A'+a[i]-10);
                }
                else printf("%d",a[i]);
            }
            printf("
    ");
            return 0;
    }
    
    

    明天一定雪耻!!!!!!!!!!!!!

  • 相关阅读:
    VS2015预览版中的C#6.0 新功能(一)
    REST总结
    MVC和传统的以模板为中心的web架构比较
    实现两个select list box间item的移动和过滤
    异步编程
    简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别
    C#导出EXCEL,并生成charts表
    CRC16位校验
    c# 后台GET、POST、PUT、DELETE传输发送json数据
    UDP通讯
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12799121.html
Copyright © 2011-2022 走看看