首页 > 其他分享 >手写to_string()

手写to_string()

时间:2022-10-09 15:37:11浏览次数:40  
标签:tmp 10 string int tostring 手写 include

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

string my_tostring(int x)
{
    vector<char> tmp;

    while (x)
    {
        tmp.push_back(x % 10 + '0');
        x /= 10;
    }
    reverse(tmp.begin(), tmp.end());

    string s = "";
    for (auto c : tmp)
        s += c;
    return s;
}

int main()
{
    int n;
    cin >> n;

    string s = my_tostring(n);

    cout << s;

    system("pause");
    return 0;
}

标签:tmp,10,string,int,tostring,手写,include
From: https://www.cnblogs.com/rdisheng/p/16772285.html

相关文章

  • String、StringBuffer 、StringBuilder、StringJoiner
    一、String、StringBuffer、StringBuilder1、定义用来连接多个字符的,本质就是一个char型的数组,是一种引用类型,并且不能被继承因为是final修饰的Stringstr="abc";相当......
  • 手写线程池
     我们先不去看线程池原理,然后自己一步一步的分析,看看线程池都需要做哪些工作。 然后再一步一步的实现它,然后再去对比比人写好的线程池,然后看看差距在哪里。 ## 先分析......
  • abc272_f Two Strings (后缀数组)
    https://atcoder.jp/contests/abc272/tasks/abc272_f将SS#TT在字符串中排序,看标号为1-n后面有多少2n+2-3n+1的标号然后就会注意题目要的是小于等于,那么要拼成SS......
  • #yyds干货盘点#慎用JSON.stringfy
    项目中遇到一个bug,一个组件为了保留一份JSON对象,使用JSON.stringify将其转换成字符串,这样做当然是为了避免对象是引用类型造成数据源的污染。但发现后面使用JSON.pars......
  • 35+,如果面试让我手写红黑树!
    作者:小傅哥博客:https://bugstack.cn沉淀、分享、成长,让自己和他人都能有所收获!......
  • net中c#教程 string字符串的常用操作
    无论是用net语言,还是java语言,即使用python、php语言,string字符串操作都是最基础的,本博客主要是面对string的教程,希望对小伙伴们有帮助。因为是工作经验的总结,所以博客会不......
  • [Oracle] LeetCode 205 Isomorphic Strings
    Giventwostringssandt,determineiftheyareisomorphic.Twostringssandtareisomorphicifthecharactersinscanbereplacedtogett.Alloccurrence......
  • String忽略大小写方法compareToIgnoreCase源码及Comparator自定义比较器
    String忽略大小写方法compareToIgnoreCase源码及Comparator自定义比较器//源码publicintcompareToIgnoreCase(Stringstr){returnCASE_INSENSITIVE_O......
  • 手写一个AQS实现
    1.背景2.代码-基础准备2.1.Node节点对象创建在MyReentrantLock对象内建立一个Node节点对象,后面作为双向链表的节点;publicclassMyReentrantLock{/***......
  • Codeforces.1305B Kuroni and Simple Strings[模拟]
    题面NowthatKuronihasreached10yearsold,heisabigboyanddoesn'tlikearraysofintegersaspresentsanymore.ThisyearhewantsaBracketsequencea......