当前位置:网站首页>[common skills]
[common skills]
2022-07-24 05:27:00 【rejudge】
Here's the catalog title
solve scanf Eat back
getchar()
Input n Back carriage return , the second scanf Carriage return will be assigned to op. Use getchar() Get the carriage return first .
#include<iostream>
#include<cstdio>
using namespace std;
char n;
char op;
scanf("%c",&n);
getchar();
scanf("%c",&op);
char op[2]
char op[2];
char num;
scanf("%s",op);
scanf("%c",num);
cout<<op<<' '<<num;
Keep the specified decimal places
- C++ cout Output specified decimal places
#include<iomanip>
cout<<setiosflags(ios::fixed)<<setprecision(3);
cout<<2.1<<endl; // Output 2.100
- C++ printf Output specified decimal places
#include<cstdio>
printf("%.3f",2.1); // Output 2.100
character string 、 Array
- int Array Allocate space size
int num[10]={
0,1};
cout<<sizeof(num)/sizeof(num[0]);
// Output 10
- String length
string str="123";
cout<<str.length();
// Output 3
- character string turn char Array
#include<cstring>
char a[3];
string str="123";
strcpy(a,str.c_str());// Be careful .c_str()
for(int i=0;i<3;i++)
cout<<a[i]<<' ';
// Output 1 2 3
- Count and character string Interturn
#include<sstream>
string tostr(int n)
{
stringstream ss;
ss<<n;
string str;
ss>>str;
return str;
}
int toint(string str)
{
stringstream ss;
ss<<str;
int num;
ss>>num;
return num;
}
- Enter a line of string containing spaces
getline(cin,str);
gcd&lcm
- Two numbers of gcd
int gcd(int a,int b)
{
if(b==0) return a;
return gcd(b,a%b);
}
- More than one number of gcd
for(int i=0;i<n-1;i++)
{
a[0]=gcd(a[i],a[0]);
}
// More than one number of gcd There is a[0]
- Minimum common multiple
int lcm(int a,int b)
{
return a*b/gcd(a,b);
return a/gcd(a,b)*b; // More reasonable , prevent a*b overflow
}
sort Sort
- Default from small to large
sort(num,num+8);
- Custom functions from large to small
int cmp(int a,int b)
{
return a>b;
}
sort(num,num+8,cmp);
边栏推荐
- Installation and login login
- day(0~6)代表每月第一天起始位置,stop代表每月天数,每天之间空两个空格。输入不同的day和stop,输出每月日历的样子。假设day为2,stop为31,则输出样式为
- Learn AI linear regression from Li Mu. The code implementation from scratch is super detailed
- Some experience of using D2L package and related environment configuration
- JMeter upload and download files
- 线程的介绍
- 【sklearn】PCA
- Jersey2.25.1集成freemarker
- JSP+Dao整合
- 程序员工具合集!(转载)
猜你喜欢
随机推荐
使用d2l包和相关环境配置的一些血泪心得
Redis的使用
移动软件开发-iso简易微信
C语言从入门到入土(一)
02-移动端页面适配
反射的介绍
Create and delete databases using databases
OPENGL在屏幕上绘制2个点,右边一个蓝色的点,采用反走样技术,左边一个红色的点,不采用反走样技术。比较两个点的区别。
深度剖析数据在内存中的存储
C语言从入门到入土——函数
Generator generator, which generates only two methods
JDBC encapsulates a parent class to reduce code duplication
Relational database 10 minutes to understand MySQL
Installation and login login
JMeter FAQs
Text summary acl2021
线程的介绍
3. 在屏幕上绘制一个底是正方形的五面锥体,锥体的底面在XOZ平面上,锥顶在Y轴上。用下图给锥体的四个三角形面做纹理映射,使得锥体的四个面分别是红橙黄绿色。
关于numpy基础用法的一个整理
赶紧进来!!轻松掌握C语言“顺序”、“分支”、“循环”三大结构









