360校园招聘
来源:互联网 发布:吉他伴奏器软件 编辑:程序博客网 时间:2024/04/29 01:21
题目:
题目很简单,就是统计在1-n之间所有只由0和1构成的整数,例如
1 10 11
100 101 110 111
1000 1001 1010 1011 1100 1101 1110 1111
代码:
#include<iostream>#include<vector>#include<map>#include<set>#include<sstream>#include<fstream>#include<cstring>#include<iomanip>#include<stack>#include<algorithm>using namespace std;int count_num(int num,set<int>&data){int count = 0;for (set<int>::iterator iter=data.begin(); iter!=data.end(); iter++){if (*iter<= num)count++;}return count;}int main(){ifstream fin("C:\\Users\\Dell\\Desktop\\data.txt");int num;set<int>data;data.insert(1);data.insert(10);data.insert(11);int now = 11;int count = 2;while (now<=pow(10,9)){int base = pow(10, count);int size = data.size();data.insert(base);set<int>::iterator iter = data.begin();while(size){data.insert(base+(*iter));iter++;size--;}count++;now = *(--data.end());}while (fin >> num){cout << count_num(num,data) << endl;}return 0;}编码的过程中可能要用到将数字转化成字符串,下面是一些可行的办法:
#include<iostream>#include<vector>#include<map>#include<set>#include<sstream>#include<fstream>#include<cstring>#include<iomanip>#include<stack>#include<algorithm>using namespace std;//方法1int main(){ifstream fin("C:\\Users\\Dell\\Desktop\\data.txt");unsigned long long num;string str;stringstream mystream;while (fin>>num){mystream << num;mystream >> str;cout << str << endl;mystream.clear();}return 0;}//方法2int main(void){int number = 12345;char string[32];_itoa_s(number, string, 10);printf("integer = %d string = %s\n", number, string);return 0;}
0 0
- 360校园招聘
- 360 2015校园招聘
- 360校园招聘笔试题
- 校园招聘
- 校园招聘
- 360安全卫士2011校园招聘信息
- 校园招聘--奇虎360笔试
- 奇虎360 2014校园招聘面试
- 360校园招聘2016笔试题
- 360公司2016校园招聘笔试题大题一
- 360公司2016校园招聘笔试题大题一
- 校园招聘会
- 金山校园招聘会
- IBM校园招聘
- 淘宝 校园招聘题目
- 校园招聘(笔试)
- 校园招聘(机试)
- 校园招聘(面试)
- Cesium学习(4)--使用gdal2srtmtiles-demo.py生成高程数据
- 【poj2773】 Happy 2006
- higher-ordering cluster的C语言实现
- JPEG JPG
- 39. 40.Combination Sum
- 360校园招聘
- java基础之枚举
- leetcode 62. Unique Paths
- Android Volley 灵活应用由浅入深
- 第一行代码第三日
- UOJ 13|【UER #1】跳蚤OS|字典树
- 布局新成员:ConstraintLayout
- React Native
- Java实现发邮件功能