当前位置:网站首页>PAT1001

PAT1001

2022-08-09 11:09:00 AlanLiu6

https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400

好久没刷过题了,手感十分生疏,以前的都忘光了,先刷刷题试试手感

#include<cstdio>
#include<cstring>
#include<stdlib.h>


int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
 // printf("%d %d",a,b);
    int c = a+b;
    char str[100];
 //   itoa(c,str,10);
    /*
        itoa函数功能详解
        itoa(c,str,10)
        三个输入的意思为 :
        第一个 要转化的整数
        第二个 要存入的字符串
        第三个 转换后的进制位 这里为10进制
    */
    sprintf(str,"%d",c);
    /*

    sprintf 功能详解
    sprintf(str,"%d%f%s",a,b,c);
    即先不看 str的内容,将此函数视为printf输出按格式abc,
    这里只是将输出的abc存到了str中




    */
  //  printf("%s  ---   %d\n",str,strlen(str));
    char ans[16] = " ";

    int flag =0;
    for(int i = strlen(str)-1,j = 0;i >=0;i--,j++)
    {

     //   printf("i: %d  ans:%d\n",i,strlen(ans));
        if(flag ==3 && str[i]!= '-')
        {
            ans[j] = ',';
            j++;
            flag =0;

        }
        ans[j] = str[i];
        flag++;

    }
    for(int i = strlen(ans)-1;i>=0;i--)
        printf("%c",ans[i]);

    printf("\n");

    return 0;
}





原网站

版权声明
本文为[AlanLiu6]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Alen666/article/details/95337678