b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

c++ strchr函数_strchr函数返回_模拟实现strchr函数(23)

电脑杂谈  发布时间:2017-02-28 08:29:56  来源:网络整理

char a[100];

gcvt(number,10,a);

cout<<"integer= "<<number<<" string="<<a<<endl;

return 0;

}

输出结果:

integer= 123457 string= 123456.67

#include<iostream>

#include<cstring>

#include<sstream>

using namespace std;

int main()

{

std::string name("12345");

int age = 27;

stringstream os;

os << age;

os >> name;

// name:27

cout<<name<<endl;

return 0;

}

输出结果;

27

#include<iostream>

#include<cstring>

#include<sstream>

using namespace std;

int main()

{

stringstream ss_stream;

char sz_buf[5];

ss_stream << 88888;

ss_stream >> sz_buf; // 直接将数输出到sz_buf字符数组中

for(int i=0;i<5;i)

cout<<sz_buf[i]<<" ";

cout<<endl;

return 0;

}

输出结果:

8 8 8 8 8

输入n个整数和一个正整数k(1<=k<=n),输出这些整数从小到大排序后的第k个(例如,k=1就是最小)。n<=10*e7

#include<iostream>

#include<cmath>

#include<cstdlib>

using namespace std;

// 快速选择,平均时间复杂度O(N)

typedef int DataType;

#defineSWAP(x,y) {DataType t=x;x=y;y=t;}

intquickSelect( DataType* A, int beg, int end, int K )

{

DataType pivot;

int i, j;

if ( end - beg 1 < K ) // error

{

cout<<"error!"<<endl;

exit(0);

}

pivot = A[beg];

i = beg;

j = end 1;

// 将数组分为小于pivot和大于pivot的两部分

for ( ;; )

{

while(A[i] < pivot );

while(A[--j] > pivot );

if( i > j ) break;

SWAP(A[i], A[j] );

}

SWAP( A[beg], A[j] );

if ( j - beg == K-1 )// 如果小于pivot的数目刚好为K-1个,这返回该pivot


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34960-23.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...