Tips: 如何贴代码

22
7

最近发现大家在贴代码时遇到了些障碍。
如果你要贴一段代码,推荐的操作是:

  1. 贴到编辑框
  2. 选中这段代码
  3. 点击工具栏的代码图标"{}"

这样就能PO出格式正确的代码了

  • 发现好多人都不懂Markdown,刚刚临时做了个Markdown基础语法演示:https://github.com/tangxiadi/markdown-grammar

  • #include<iostream>

  • 没看到代码图标{}

  • {#define NUMBERMAX 26 using namespace std;}

  • 添加评论
  • reply

20 answer(s)

0
#include<yyr_AK_IOI.h>
0
int main()
0

bold italic bold&italic

  • a
  • b

github

居然支持 Markdown 基本语法……除了最重要的代码块。

0

#include <stdio.h> int main() { return 0; }

哇!刚刚才发现这里居然支持markdown语法

啦啦啦~

$M$

Dreamwings

#include <stdio.h>
int main()
{
    return 0;
}
0
#include <iostream>

include

using namespace std; typedef long long Long; Long GCD(Long a, Long b) { if (b == 0) return a; return GCD(b, a%b); } int main() { Long N = 0, M = 0; Long countN = 0, countM = 0, countEqu = 0, nume = 0, deno = 0; cin >> N >> M; Long sqN = sqrt(N), sqM = sqrt(M); if (sqN > sqM) { Long temp = sqN; sqN = sqM; sqM = temp; } for (Long i = 1; i <= sqN; i++) if (N % i == 0) { countN += 2; if (i * i == N) countN--; if (M % i == 0) countEqu++; if (M%(N/i) == 0 && (N/i) != i) countEqu++; } for(Long i = 1; i <= sqM; i++) if (M % i == 0) { countM += 2; if (i*i == M) countM--; } nume = countEqu; deno = countN * countM; Long gcd = GCD(nume, deno); nume = nume / gcd; deno = deno / gcd; cout << deno << " " << nume; return 0; }

0

```c

include

```

0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <functional>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vvi> vvvi;
typedef  pair<int,int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000000007;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
//const int maxn = 10005;

int n, t;    
vvi xyzs;
    vvi di = {
        {0,1,0},{0,-1,0},
        {1,0,0},{-1,0,0},
        {0,0,1},{0, 0, -1}
    };
    vi& operator += (vi& a, vi b) {
        for(int i = 0; i < 3; i++) a[i]+= b[i];
        return a;
    }

    struct node{
        vi xyz;
        bool isb;
        node():xyz(3, 101), isb(false){};
        node& operator = (const vi& a) { xyz = a; return *this;}
    };

    node cube[102][102][102];
    vi far = {101,101,101};
    vi find(vi d) {
        node& now = cube[d[0]][d[1]][d[2]];
        if(equal(d.begin(), d.end(), now.xyz.begin())) return d;
        else return now.xyz = find(now.xyz);
    }
    void unite(vi a, vi b) {
        a = find(a);
        b = find(b);
        if(equal(a.begin(), a.end(), b.begin())) return;
        else if(equal(a.begin(), a.end(), far.begin())) {
            cube[b[0]][b[1]][b[2]] = a;
        } else cube[a[0]][a[1]][a[2]] = b;
    }


    int maxx = 0, maxy = 0, maxz = 0;
    void clearsolve() {
        for(auto p: xyzs) {
            cube[p[0]][p[1]][p[2]].isb = false;
        }
    }
    bool solve() {
        maxx = maxy = maxz = 0;
        for(auto p: xyzs) {
            bool cab = false;
            for (int i = 0; i < 6 &&!cab; i++) {
                auto np = p;
                np += di[i];
                cab = cube[np[0]][np[1]][np[2]].isb;
            }
            if(!cab)
                return false;
            cube[p[0]][p[1]][p[2]].isb = true;
            maxx = max(maxx, p[0]);
            maxy = max(maxy, p[1]);
            maxz = max(maxz, p[2]);
        }
        maxx++, maxy++,maxz++;
        for (int i = 0; i <= maxx; i++) for(int j = 0; j <= maxy;j++) for(int z = 1; z <= maxz; z++) {
            if(i == 0||i == maxx || j == 0|| j==maxy||z==maxz) cube[i][j][z] = far;
            else cube[i][j][z] = vi{i,j,z};
            if(cube[i][j][z].isb) continue;
            if(i > 0 && !cube[i - 1][j][z].isb) unite({i, j, z}, {i-1,j,z});
            if(j > 0 && !cube[i][j - 1][z].isb) unite({i, j, z}, {i, j - 1, z});
            if(z > 1 && !cube[i][j][z-1].isb) unite({i, j, z}, {i, j, z - 1});
        }
        for (int i = (int)xyzs.size() - 1; i >= 0; i--) {
            bool can = false;
            for(int j = 0; j < 6 &&!can; j++) {
                auto next = xyzs[i];
                next += di[j];
                if(cube[next[0]][next[1]][next[2]].isb) continue;
                next = find(next);
                can = equal(next.begin(), next.end(), far.begin());
                if(can) {
                    unite(next, xyzs[i]);
                    cube[xyzs[i][0]][xyzs[i][1]][xyzs[i][2]].isb = false;
                }
            }

            if(!can) {
                return false;
            }
        }
        return true;
    }
    int main() {
        scanf("%d", &t);
        for(int i = 0; i <= 101; i++) for(int j = 0; j <= 101; j++) {
            cube[i][j][0].isb = true;
        }
        while (t--) {
            scanf("%d", &n);
            xyzs.resize(n, vi(3));
            for (int i = 0; i < n; i++) {
                for(int j = 0; j < 3; j++) scanf("%d", &xyzs[i][j]);
            }
            printf("%s\n", solve()?"Yes":"No");
            clearsolve();
        }
        return 0;
    }
0

using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace A1175 { class Program {

    static int n;
    static int m;
    static int k;
    static long result = 0;
    static ArrayList point = new ArrayList();            //记录无输入点

    static void Main(string[] args)
    {
        string tmp = Console.ReadLine().Trim();
        string[] t = tmp.Split(new char[] { ' ' });
        n = int.Parse(t[0]);
        m = int.Parse(t[1]);
        k = int.Parse(t[2]);
        int[] duArray = new int[n + 1];              //记录病毒数
        int[] father = new int[n + 1];               //记录输入路线
        ArrayList[] pathArray = new ArrayList[n + 1];            //记录输出路线
        int c;

        duArray[0] = 0;
        father[0] = 0;
        pathArray[0] = new ArrayList();

        //全部点写入无输入点集合   
        for (int i = 1; i <= n; i++)
        {
            pathArray[i] = new ArrayList();
            duArray[i] = 0;
            father[i] = 0;
            point.Add(i);
        }

        //所有点的初始病毒数
        tmp = Console.ReadLine().Trim();
        t = tmp.Split(new char[] { ' ' });
        for (int i = 0; i < k; i++)
        {
            duArray[int.Parse(t[i])]++;
        }

        //所有点的输出路线
        for (int i = 1; i <= m; i++)
        {
            tmp = Console.ReadLine().Trim();
            t = tmp.Split(new char[] { ' ' });

            pathArray[int.Parse(t[0])].Add(int.Parse(t[1]));    //记录每条路线
            father[int.Parse(t[1])]++;              //到达点父线+1
            if (point.Contains(int.Parse(t[1])) == true)
            {       //无输入点如果包含父线不为0的点
                point.Remove(int.Parse(t[1]));
            }
        }

        //无输入点不为空进入循环
        while ((c = FindPoint(point)) != -1)
        {
            if (pathArray[c].Count ==0) {
                point.Remove(c);
                continue;
            }

            foreach (int x in pathArray[c])
            {
                duArray[x] += duArray[c];
                father[x]--;
                if ((point.Contains(x) == false) && (father[x] == 0))
                {
                    point.Add(x);
                }
            }
            point.Remove(c);
            pathArray[c].Clear();
        }

        foreach (int y in duArray)
        {
            result += y;
        }

        Console.WriteLine(result);
        Console.ReadKey();

    }

    static int FindPoint(ArrayList iii)
    {
        if (iii.Count == 0)
        {
            return -1;
        }

        return (int)iii[0];

    }

}

}

enter code here
0
#include <stdio.h>
int main() {
    puts("hello, hiho");
    return 0;
}
0
#include <set>

include

include

include

include

using namespace std;

const int N=10; bool vis[N]; set ans;

void dfs(int u,int n,int cnt,string s){ if(cnt==n){ ans.insert(s); return ; } for(int i=1;i<=n;i++){ if(vis[i]) continue; char c=i+'0'; vis[i]=true; if(i>u) dfs(i,n,cnt+1,(s+c)); vis[i]=false; if(s[s.size()-1]!='-'){ dfs(-1,n,cnt,(s+"-")); } } }

int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ vis[i]=true; char c=(i+'0'); string s=""; dfs(i,n,1,s+c); vis[i]=false; } cout< ::iterator it; for(it=ans.begin();it!=ans.end();it++) cout<<*it<

0
#include
0

"include"

0
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
        }
    }
}
0

Lover

0

hello

0

考古

0
TEST
0

{#define NUMBERMAX 26

using namespace std;}

0
#define NUMBERMAX 26

using namespace std;
0

???

write answer 切换为英文 切换为中文


转发分享