整数转化为整数字符串
2015-07-29 23:44
211 查看
题目:把一串整数转化为整数字符串,并且不用itoa。
还有的题目是把整数字符串转化为整数。有空再补上。
有更好的方法,希望能分享一下。
还有的题目是把整数字符串转化为整数。有空再补上。
#include<iostream> #include<stdio.h> const int N = 10; int main() { int num = 123456789, i = 0, j = 0; //std::cin >> num; char temp ,Str ; while(num){ temp[i++] = num%10 + '0';// + '0',自动转化 ,num%10 求最后一位 num = num/10;//去除最后一位 } temp[i] = 0; printf("temp is %s\n",temp); //std::cout << "temp is " << temp << std::endl; i = i -1;//回退一位到数字位上 while(i>=0){ Str[j++] = temp[i--]; } //最后一位完后,此时i为负一,跳出循环 Str[j] = 0; //std::cout << i << std::endl; printf("temp is %s\n",Str); //std::cout << "temp is " << SStr << std::endl; }
有更好的方法,希望能分享一下。
相关文章推荐
- 关于ios开发中的分模块开发
- Single Number
- 7.29学习
- js 四种函数调用模式
- Java关键字final、static使用总结
- 《一起学》系列
- 快速幂(C语言实现) 超详细
- 技术积累
- 解开Android应用程序组件Activity的"singleTask"之谜
- Java学习--(四)新的数据类型:类(class);field,method
- 数据库相关(2)
- 【LeetCode】228 - Summary Ranges
- 学习心得三
- pagerAdapter的不同使用方法
- HDOJ Attack 4031【树状数组】
- ThinkPHP的缓存 F方法
- JDK之jstat的用法
- python 项目 Memory game
- Linux环境编程资源总结
- Android中Service与Thread的区别