常用的
liuchenjane
这个作者很懒,什么都没留下…
展开
-
各种输入输出
c++常用:#include fstream.h>ifstream filein("data.in"); // 定义一个文件输入流ofstream fileout("data.out"); //cout --> fileoutfilein.eof() //文件到末尾,返回非零值data.in表示输入的数据文件本地测试的话本来输入的数据就要在这个文件里面测转载 2016-10-11 11:01:30 · 309 阅读 · 0 评论 -
C++中的pair对组
pair将两个值视为一个单元,使用pair可以来管理键值/实值(key/value)的成对元素。 pair实现的简易代码:#include <iostream>#include <string>#include <cstring>using namespace std;template <class T1,class T2>struct Pair{ //type names fo原创 2016-10-17 14:56:53 · 473 阅读 · 0 评论 -
C/C++字符串与数字的相互转化
数字转字符串: 用C++的stringstream:#include <sstream>#include <string> string num2str(double i) { stringstream ss; ss << i; return ss.str(); }字符串转数字int str2num(string s){ int num; string转载 2016-10-17 09:39:24 · 4706 阅读 · 0 评论 -
Linux文件打包和压缩
文件后缀名 说明 *.zip zip程序打包压缩的文件 *.rar rar程序压缩的文件 *.7z 7zip程序压缩的文件 *.tar tar程序打包,未压缩的文件 *.gz gzip程序(GNU zip)压缩的文件 *.xz xz程序压缩的文件 *.bz2 bzip2程序压缩的文件 *.tar.gz tar打包,gzip程序压缩的文转载 2016-10-12 11:09:54 · 1199 阅读 · 0 评论 -
Using Cyclic Replacements解决数组原址移动问题
Using Cyclic Replacement问题1:Rotate Array=>Rotate an array of n elements to the right by k steps.void rotate(vector& nums, int k) { int n=nums.size(); k=k%n; int start;原创 2016-10-12 09:31:24 · 835 阅读 · 0 评论 -
Reverse Linked List
Reverse Linked ListReverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?解法1:迭代转载 2016-09-26 10:19:31 · 284 阅读 · 0 评论 -
Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as yo翻译 2016-09-25 22:00:16 · 311 阅读 · 0 评论 -
Rotate List
61. Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.回想rotate Arr原创 2016-09-26 15:19:23 · 250 阅读 · 0 评论 -
215. Kth Largest Element in an Array
Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example, Given [3,2,1,5,原创 2016-10-08 21:17:00 · 217 阅读 · 0 评论 -
求最大公约数和最小公倍数
辗转相除法如果a>b,gcd(a,b)=gcd(b,r),其中r=a%b.int gcd(int a,int b)//最大公约数{if (a<b) return gcd(b,a);else if (b==0) return a;else return gcd(b,a%b);}int lcm(int a,int b){re转载 2016-10-11 10:35:11 · 258 阅读 · 0 评论 -
C语言printf()函数:格式
转载于C语言中文网 头文件:#include #include<stdio.h>int main(void){ int a=1; float b=5.0; char str[100]= ""; scanf("%c %c %c",&a,&b,str); /*分别演示 整数*/ printf("int is:%d\n",a); /*分别演示转载 2017-03-14 19:30:05 · 703 阅读 · 0 评论