前言
偶然间看到了一个算法从事者分享的文章,让我也对算法从事有了很大的兴趣,接着考研,我可以将计算机的基础好好的学一遍,因为自己打算在3月考研全面铺开,于是我有2个月的时间去学习算法,那么现在开始把
C/C++快速回顾
因为刷题的话,自己打算使用上述两个语言,所以我们这里先来快速过一遍
第一个程序
#include<stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d", a + b);
return 0;
}
字符
#include<stdio.h>
int main()
{
char c1 = 'z', c2 = 'j', c3 = 117;
printf("%c%c%c", c1, c2, c3);
return 0;
}
》》zju
字符串
#include<stdio.h>
int main()
{
char str1[25] = "wo ai de ren bu ai wo!";
printf("%s\n", str1);
return 0;
}
强制类型转化
#include<stdio.h>
int main()
{
double r = 12.56;
int a = 3, b = 5;
printf("%d\n", int(r));
printf("%d\n", a / b);
printf("%.1f\n", double(a) / double(b));
return 0;
}
符号常量
#include<stdio.h>
#define pi 3.14
//const double pi = 3.14
int main()
{
double r = 3;
printf("%f", pi * r * r);
return 0;
}
scanf字符数组
#include<stdio.h>
int main()
{
char str1[10];
scanf("%s", &str1);
printf("%s", str1);
return 0;
}
》》abcd efg
》》abcd
scanf空格
#include<stdio.h>
int main()
{
int a;
char c, str1[10];
scanf("%d%c%s", &a, &c, str1);
printf("a=%d,c=%c,str=%s", a, c, str1);
return 0;
}
》》10 s df
》》a=10,c= ,str=s
printf %md
#include<stdio.h>
int main()
{
int a = 123, b = 1234567;
printf("%5d\n", a);
printf("%5d", b);
return 0;
}
>> 123
>>1234567
printf %0md
#include<stdio.h>
int main()
{
int a = 123, b = 1234567;
printf("%05d\n", a);
printf("%05d", b);
return 0;
}
>>00123
>>1234567
getchar,putchar
#include<stdio.h>
int