zoukankan      html  css  js  c++  java
  • pat甲级 1001 A+B Format

    要写甲级题,首要任务是解决英文这个大难题。

    困难词汇(我不认识的):calculate计算  standard format 标准格式  digits数字  separated 分离  commas逗号

    这道题的大致意思是,给出两个数a和b,并且a和b都大于等于-10的6次方小于等于10的6次方,求出a和b的和,将这个和,每三个数字用逗号分隔一下。看懂了题意以后这题就简单了

    ac代码如下:

    #include <iostream>
    #include<string>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
        int a,b;
        cin>>a>>b;
        int c=a+b;
        string e=to_string(c);//e是a和b的和
        string d;
        for(int i=e.length()-1,j=0;i>0;j++,i--){//将e的数给d,每三个加上一个,号
            d+=e[i];
            if((j+1)%3==0&&e[i-1]!='-'){//如果e[0]是-的时候是不用给逗号的
                d+=',';
            }
        }
        d+=e[0];
        for(int i=d.length()-1;i>=0;i--){
            cout<<d[i];
        }
    }
  • 相关阅读:
    jichu
    scanf
    数位dp
    hdu 5667
    华东交通大学2018年ACM“双基”程序设计竞赛 K
    华东交通大学2018年ACM“双基”程序设计竞赛 D
    map
    次小生成树
    set
    c++11之为什么C++11引入了std::ref?
  • 原文地址:https://www.cnblogs.com/fromzore/p/9949037.html
Copyright © 2011-2022 走看看