codeforces672 A (数字转换成字符串)
来源:互联网 发布:卷皮折扣和淘宝那个好 编辑:程序博客网 时间:2024/06/10 04:34
把数字转换成字符串,一种写法to_string但编译器不一定支持。
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <string>#include <vector>#include <stack>#include <bitset>#include <cstdlib>#include <cmath>#include <set>#include <list>#include <deque>#include <map>#include <queue>using namespace std;typedef long long ll;int main (){ int i; string s; for(i=1;i<=1000;i++){ if (s.size() > 1000) break; int num = i; s+= to_string (num); } int n; cin >> n; cout << s[n-1]; return 0;}
另外一种写法
include <bits/stdc++.h>
using namespace std;
template<typename T> string toString(const T& t){
ostringstream oss; //创建一个格式化输出流
oss<<t; //把值传递如流中
return oss.str();
}
int main()
{
string str;
int i=1;
string s;
while(1)
{
s=toString(i);
str=str+s;
if(str.length()>=1000)
break;
i++;
}
int n;
scanf("%d",&n);
cout<<str[n-1]<<endl;
return 0;
}
阅读全文
0 0
- codeforces672 A (数字转换成字符串)
- 数字转换成字符串
- 数字转换成字符串
- 数字转换成字符串
- 数字转换成字符串
- 数字转换成字符串
- 数字转换成字符串
- 数字转换成字符串
- 数字字符串转换成整数
- 数字转换成字符串函数
- java 数字转换成字符串
- python 数字转换成字符串
- java数字转换成字符串
- java 数字转换成字符串
- jstl 数字转换成字符串
- java 数字转换成字符串
- 字符串转换为数字:String:convert a string to int
- A + B问题(字符串与数字之间的转换)
- 最少货币数问题
- 进程fork和vfork函数复习
- Dialvik/ARP(ANDROID)中的多线程机制(3)
- js对象、继承,原型链相关知识及应用心得
- Yii2 中模块相关配置
- codeforces672 A (数字转换成字符串)
- 顺序结构的队列
- 220. Contains Duplicate III
- eclipse 启动报错问题,整理could not create java virtual machine a fatal exception has occured
- tensorflow 安装中遇到的问题
- WKWebView 实例
- 链队列
- 使用 Instruments 做 iOS 程序性能调试
- JAVA mongodb工具类