[09/25]

除数  /   余数 %

和符号  &&

最大数      0xfffffff

小数点 

#include<iomanip>     /* 头文件 */
double  a;
cout<<setiosflags(ios::fixed)<<setprecision(1)<<a<<endl;
                                                            /* 一位小数点   */
小数点

 if 语句

int a;
if(a>0)    xxxxxx;
else if()    xxxxx;
else     xxxxxx;

 洛谷 1008 不会写 

洛谷 1980   函数的用法   传送门

#include<iostream>
using namespace std;
int n,x,sum=0;
int work(int n)
{
    int ans=0;
    for(;n>0;)
    {
        if(n%10==x)    ans++;
        n/=10;
    }
    return ans;
}
int main()
{
    cin>>n>>x;
    for(int i=1;i<=n;i++)
        sum+=work(i);
    cout<<sum<<endl;
    return 0;
}
1980

 int 范围   -2^32 ~ 2^32-1

long long  -2^63 ~ 2^63-1

字符串 

#include<string>    //头文件
string s;    //s:abcd
//s的长度为4
s.size()=4;
//0,1,2,3;

cin输入的字符串 到空格就停止了
这时候用string的库,调用getline直接读入一整行带空格
getline(cin,s);
若A为1,B为2; s
-‘A‘+1; a为1,b为2; s-’a’+1

if(a)  如果a不等于0就继续  

if(!a)  如果a等于0就继续  a==0,!a不等于0

【10/07】  写了一下午的字符串,想起来两年前noip因为读入字符串少拿10分,加油加油再加油啊!

数字反转  传送门  

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    char p=0;
    int fu=0,mo=0,x=0;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]>='0'&&s[i]<='9')    fu++;
        else    {
            p=s[i];
            break;
        }
    }
    //cout<<fu<<endl;
    x=fu;//fu会跑,要记录下符号的位置。
    while(s[fu-1]=='0'&&fu-1>0)    fu--;//fu-1是最后的位数,第一次没有ac因为还有0,要确保最后剩下一位。
    for(int i=fu-1;i>=0;i--)    cout<<s[i];
    if(p!=0)    {cout<<p;
    mo=s.size()-1;
    while(s[x+1]=='0'&&x<mo-1)    x++;
    while(s[mo]=='0'&&mo>x+1)    mo--;//x是符号的位置,mo是末尾的位置,中间一定会有一位,要确保中间有两位时才会移动,剩下一位就不移动了
    for(int i=mo;i>x;i--)    cout<<s[i];
    }
    return 0;
}
View Code

挺好的没事多看看,不知道下回能不能在写出来。

排序  

#include<iostream>
using namespace std;
int main()
{
    int a[100],n,t=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n-i;j++)
        {
            if(a[j]<a[j+1])
            {    t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    for(int i=n;i>0;i--)
        cout<<a[i]<<' ';
    return 0;
}
冒泡排序
#include<iostream>
using namespace std;
int a[101],n;
void quicksort(int left,int right)
{
    int i,j,t,temp;
    if(left>right)    return;
    temp=a[left];
    i=left;
    j=right;
    while(i!=j)
    {
        while(a[j]>=temp&&i<j)    j--;
        while(a[i]<=temp&&i<j)    i++;
        if(i<j)    {
            t=a[i];
            a[i]=a[j];
            a[j]=t;
        }
    }
    a[left]=a[i];
    a[i]=temp;
    quicksort(left,i-1);
    quicksort(i+1,right);
    return;
}
int main()
{
    int i,j;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    quicksort(1,n);
    for(int i=1;i<=n;i++)
        cout<<a[i]<<' ';
    return 0;
}
quicksort

判断素数 

bool zhi(int x)
{
    if(x<2)    return 0;
    else    {
        for(int i=2;i*i<=x;i++)
            if(x%i==0)    return 0;
    }
    return 1;
}
质数

判断是否回文

bool hui(int x)
{
    int y=x,ans=0;
    for(;y>0;)
    {
        ans=ans*10+y%10;    y=y/10;
    }
    if(ans==x)    return 1;
    else    return 0;
}
回文

 队列的基本用法

#include "pch.h"
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int main()
{    
    int n, a[50];
    cin >> n;
    int head = 1, tail = n+1;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    while (head < tail)
    {
        cout << a[head] << " ";
        head++;
        a[tail] = a[head];
        head++;
        tail++;
    }
    return 0;
}
队列

#include "pch.h"
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int main()
{
    char a[50], s[50];
    cin >> a;
    int len = strlen(a), mid, next, top = 0;
    mid = len / 2 - 1;
    for (int i = 0; i <= mid; i++)
        s[++top] = a[i];
    if (len % 2 == 0)
        next = mid + 1;
    else next = mid + 2;
    for (int i = next; i < len; i++)
    {
        if (a[i] != s[top])    break;
        top--;
    }
    if (top == 0)    cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}
No matter how you feel, get up , dress up , show up ,and never give up.
原文地址:https://www.cnblogs.com/Kaike/p/9702977.html