![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
OJ
GuoMengKai
这个作者很懒,什么都没留下…
展开
-
vector之assign
#include <iostream>#include <vector>using namespace std;int main() { int n; vector<int> a,b(1),c(1); a.push_back(1); a.push_back(2); a.push_back(3); b[0]=66; c[0]=84; b....原创 2019-03-03 15:50:30 · 781 阅读 · 0 评论 -
将string转化为int
#include&lt;iostream&gt;#include&lt;string&gt;using namespace std;int main(){ string s="652s23"; int i=atoi(s.c_str()); cout &lt;&lt; i;//652 return 0;}原创 2019-03-01 10:23:43 · 823 阅读 · 0 评论 -
printf用法补录
printf属于c语言,而string类型属于c++,故string不可由printf直接输出,虽然可以用.c_str()来转换,但这很不c++,故需在输出string类型时用cout。原创 2019-03-01 10:27:53 · 86 阅读 · 0 评论 -
sort用法补录
//sort在作用于数组与vector时方式不同int a[100];sort(a,a+50,cmp);vector&amp;lt;int&amp;gt; b(100);sort(b.begin(),b.end(),cmp)原创 2019-03-01 10:41:50 · 97 阅读 · 0 评论 -
STL之map定义,使用与遍历
#include&amp;amp;lt;iostream&amp;amp;gt;#include&amp;amp;lt;map&amp;amp;gt;using namespace std;int main(){ map&amp;amp;lt;string,int&amp;amp;gt; m; m[&amp;quot;a&amp;quot;]=3; m[&原创 2019-03-01 10:42:08 · 453 阅读 · 0 评论 -
vector与数组的区别补录
int n;cin &amp;amp;gt;&amp;amp;gt; n;vector a(n);//可以定义非常量一维数组//而int b[n]则会报错,提示应输入常量表达式原创 2019-03-01 10:43:03 · 168 阅读 · 0 评论 -
求最大公约数
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}原创 2019-02-28 13:39:37 · 61 阅读 · 0 评论 -
cin之输入不定量整数
1:读入stringstream 再借助变量t输出到vector中(适用于以 \n 结尾)#include&lt;iostream&gt;#include&lt;string&gt;#include&lt;vector&gt;#include&lt;sstream&gt;using namespace std;int main(){ ios::sync_with_s原创 2019-03-01 10:24:04 · 625 阅读 · 0 评论 -
vector之清空
#include&amp;amp;lt;iostream&amp;amp;gt;#include&amp;amp;lt;string&amp;amp;gt;#include&amp;amp;lt;vector&amp;amp;gt;using namespace std;int main(){ vector&amp;amp;lt;int&amp;amp;gt; a,b(1原创 2019-03-01 10:24:22 · 2413 阅读 · 0 评论 -
cout:控制输出格式之左边补零
#include&amp;amp;lt;iostream&amp;amp;gt;#include&amp;amp;lt;iomanip&amp;amp;gt;using namespace std;int main(){ int a=6; cout &amp;amp;lt;&amp;amp;lt; setw(3) &amp;amp;lt;&amp;amp;lt; setf原创 2019-03-01 10:25:58 · 4309 阅读 · 0 评论 -
int及long long的最大值
int 2^31-1;long long 2^63-1;原创 2019-03-01 10:26:18 · 10878 阅读 · 0 评论 -
stringstream与atoi实现字符串与int,double型转换之比较
#include <iostream>#include <string>#include <sstream>using namespace std;int main() { string s="54.653"; double d=atoi(s.c_str()); cout << d << endl;//54 strings...原创 2019-03-01 13:02:18 · 149 阅读 · 0 评论 -
fin与fscanf能同时使用吗?
#include&amp;lt;iostream&amp;gt;#include&amp;lt;iomanip&amp;gt;#include&amp;lt;fstream&amp;gt;using namespace std;int main(){ FILE *fp; fp=fopen(&quot;in.txt&quot;,&quot;r&am原创 2019-03-01 10:25:46 · 199 阅读 · 0 评论 -
pta之浮点错误
即发生了( /0 || %0)的情况原创 2019-03-03 14:51:59 · 4495 阅读 · 0 评论 -
algorithm之reverse
reverse(a.begin(),a.end());(头文件 algorithm,已测vector可用)原创 2019-03-03 14:24:47 · 153 阅读 · 0 评论 -
STL之vector二维数组补录
#include&amp;amp;lt;iostream&amp;amp;gt;#include&amp;amp;lt;vector&amp;amp;gt;using namespace std;int main(){ vector&amp;amp;lt;vector&amp;amp;lt;int&amp;amp;gt;&amp;amp;gt; dp(100, vector原创 2019-03-01 10:24:34 · 82 阅读 · 0 评论 -
关于c++中的变量定义后自动初始化问题
#include&amp;amp;lt;iostream&amp;amp;gt;#include&amp;amp;lt;string&amp;amp;gt;using namespace std;int main(){ int a; int b[80]; string s; string sd[4]; char c; char cs[6]; //if(a==0) cout &amp;amp;lt;&a原创 2019-03-01 10:24:47 · 486 阅读 · 0 评论 -
vector补录之重新定义vector大小
#include<iostream>#include<string>#include<vector>using namespace std;int main(){ vector<int> a; cout << a.size() << endl;//0 a.push_back(0); a.push_back(1)...原创 2019-03-05 16:23:04 · 1432 阅读 · 0 评论 -
多行注释快捷键
先Ctrl+k 再Ctrl+c(取消 先Ctrl+k 再Ctrl+u)ps:仅测试是否适用于vs2008原创 2019-03-01 10:27:44 · 791 阅读 · 0 评论 -
多变量一行赋值
#include<iostream>#include<string>using namespace std;int main(){ int a,b; a=b=1; string sa,sb; sa=sb="sdf"; cout << a << " " << b << endl; cou原创 2019-03-05 14:49:31 · 2259 阅读 · 0 评论 -
set用法之判断是否在set里
set.find(t) == set.end()则不再set容器中。原创 2019-03-01 17:53:15 · 9354 阅读 · 1 评论 -
c++字符函数
#include字符判断函数: isdigit islower isupper isalpha(islower || isupper)字符转换函数: tolower toupper原创 2019-03-01 10:25:23 · 270 阅读 · 0 评论 -
OJ:使用cin时运行超时
c++为了兼容c,保留了c中的stdin与stdout,通过关闭其与cin与cout的同步,实现运行时间的大量减少。ios::sync_with_stdio(false);原创 2019-03-01 10:42:17 · 790 阅读 · 0 评论 -
OJ:algorithm头文件中sort函数的应用
#include&amp;lt;iostream&amp;gt;#include&amp;lt;algorithm&amp;gt;using namespace std;struct student{ int id; int grade[4];};int k;student s[2001];bool cmp(int a,int b){ return a&amp;gt;b;}bool cmp1(studen原创 2019-03-01 10:42:24 · 203 阅读 · 0 评论 -
cin输入带有间隔符的多个变量
#include&amp;lt;iostream&amp;gt;#include&amp;lt;string&amp;gt;using namespace std;int main(){ int xa,xb,xc,ya,yb,yc,za,zb,zc; char c; cin &amp;gt;&amp;gt; xa &amp;gt;&amp;gt; c &原创 2019-03-01 10:26:29 · 2413 阅读 · 0 评论 -
OJ:ifstream与ofstream实现对文件的读与写
#include&amp;lt;iostream&amp;gt;#include&amp;lt;fstream&amp;gt;#include&amp;lt;vector&amp;gt;using namespace std;vector&amp;lt;int&amp;gt; v[100];int main(){ ifstream fin; fin.open(&原创 2019-03-01 10:43:30 · 204 阅读 · 0 评论 -
OJ:stringstream实现int型与string型的相互转化
#include&amp;lt;iostream&amp;gt;#include&amp;lt;sstream&amp;gt;using namespace std;int main(){ stringstream ss; string str=&quot;22222&quot;; int a=100; ss &amp;lt;&amp;lt; a; ss &原创 2019-03-01 10:43:40 · 533 阅读 · 0 评论 -
OJ:字符串转化为int型
#include&amp;lt;iostream&amp;gt;using namespace std;int main(){ char s[100]=&quot;123&quot;; int a=atoi(s);//参数不可为字符 cout &amp;lt;&amp;lt; a; return 0;}原创 2019-03-01 10:43:46 · 133 阅读 · 0 评论 -
OJ:int型转化为字符数组
#include&amp;lt;iostream&amp;gt;using namespace std;int main(){ char ssum[10]; itoa(123,ssum,10); //第三个参数是进制 printf(&quot;%s&quot;,ssum); return 0;}原创 2019-03-01 10:42:48 · 147 阅读 · 0 评论 -
OJ:STL之vector
#include&amp;lt;iostream&amp;gt;#include&amp;lt;vector&amp;gt;using namespace std;vector&amp;lt;int&amp;gt; v(100);//()声明一维数组 且赋v[i]初值0vector&amp;lt;int&amp;gt; v2[100];//[]声明二维数组 且赋v2[i][原创 2019-03-01 10:43:56 · 148 阅读 · 0 评论 -
OJ:格式控制
printf(&quot;%02d&quot;,a);//共2位,位数不够左边用零补原创 2019-03-01 10:44:04 · 165 阅读 · 0 评论 -
OJ:STL之queue
#include&amp;lt;iostream&amp;gt;#include&amp;lt;queue&amp;gt;using namespace std;int main(){ queue&amp;lt;int&amp;gt; q; cout &amp;lt;&amp;lt; q.empty() &amp;lt;&amp;lt;原创 2019-03-01 10:44:12 · 237 阅读 · 0 评论 -
OJ:小技巧
大数组开全局,放在函数里会溢出栈原创 2019-03-01 10:45:10 · 151 阅读 · 0 评论 -
OJ:cout 控制小数点后位数
#include&amp;lt;iostream&amp;gt;#include&amp;lt;iomanip&amp;gt;using namespace std;int main(){ float f=123.456789; cout &amp;lt;&amp;lt; fixed &amp;lt;&amp;lt; setprecision(1) &am原创 2019-03-01 10:42:30 · 159 阅读 · 0 评论 -
0-15与0-A-F之间的转换
#include&amp;amp;amp;lt;iostream&amp;amp;amp;gt;using namespace std;int main(){ int ia='5'-'0'; int ib='D'-'A'+10; char ca=3+'0'; char cb=12-10+'A'; cout &amp;amp;amp;lt;&amp;amp;amp;lt; &amp;amp;quot;char to原创 2019-03-01 10:27:34 · 290 阅读 · 0 评论 -
c++ 输入一行
string s;getline(cin,s);//以换行符为结束符原创 2019-03-01 10:26:40 · 1855 阅读 · 0 评论 -
string数组定义
string s[]={“S1”,“S2”,“S3”};string s[3]={“S1”,“S2”,“S3”};string s[40]={“S1”,“S2”,“S3”};//下标3及以后的为&quot;&quot;原创 2019-03-01 10:26:59 · 2762 阅读 · 0 评论 -
map补录
#include&amp;lt;iostream&amp;gt;#include&amp;lt;string&amp;gt;#include&amp;lt;map&amp;gt;using namespace std;int main(){ map&amp;lt;int,int&amp;gt; m; m[54]=96; m[6]=84; map&am原创 2019-03-01 10:26:51 · 96 阅读 · 0 评论 -
OJ:fill的用法
#include <algorithm>using namespace std;int a[100],b[100][100];const int inf=100000;int main(){ fill(a,a+100,inf); fill(b[0],b[0]+100*100,0); return 0;}原创 2019-03-01 10:44:21 · 161 阅读 · 0 评论 -
OJ:fill的用法
#includeusing namespace std;int a[100],b[100][100];const int inf=100000;int main(){fill(a,a+100,inf);fill(b[0],b[0]+100*100,0);return 0;}原创 2019-03-01 10:44:53 · 160 阅读 · 0 评论