Tips: 如何贴代码

19
5

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

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

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

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

  • #include<iostream>

  • 没看到代码图标{}

  • 添加评论
  • reply

20 answer(s)

0
#include<cstdio>

int main() { printf("23333333333333\n"); return 0; }

0
#include<cstdio>
int main()
{
    printf("23333333333333\n");
    return 0;
}
0
#include <iostream>
0

{test}testtest

0

##include<iostream> using namespace std; int main

0
struct Node
{
    int x,y;
};

Node node[maxn];
LL nodedis[maxn];
bool flag[maxn];
1
#include <stdio.h>
#include <string.h>
1
#include <iostream>

int main(int argc, char *argv[]){
    std::cout << "Hello world!" << std::endl;
    return 0;
}
0
#include <map>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define FIN     freopen("input.txt", "r", stdin)
typedef unsigned int uint;
const int maxn = 100 + 5;
int N, M;
int tot;
string szA, szB;
map<string, int> Hash;
map<int, string> reHash;
struct Node{
    int par, son;
}Nds[maxn];
int fa[maxn];
int Find(int x) {
    return x == fa[x] ? x : (fa[x] = Find(fa[x]));
}
void Union(int a, int b) {
    int pa = Find(a), pb = Find(b);
    if(pa != pb) {
        fa[pb] = pa;
    }
}
int get_lca(int a, int b) {
    if(a == b) return a;
    if(Nds[a].par == -1) return a;
    if(Nds[b].par == -1) return b;

    if(a == Nds[b].par) return a;
    if(Nds[a].par == b) return b;
    if(Nds[a].par == Nds[b].par) return Nds[b].par;
    return get_lca(Nds[a].par, Nds[b].par);
}
int main() {
    FIN;
    while(~scanf("%d", &N)) {
        Hash.clear();
        reHash.clear();
        tot = 0;
        memset(Nds, -1, sizeof(Nds));
        for(int i = 1; i <= N; i++) fa[i] = i;
        for(int i = 0; i < N; i++) {
            cin >> szA >> szB;
            if(!Hash[szA]) {
                Hash[szA] = ++ tot;
                reHash[Hash[szA]] = szA;
            }
            if(!Hash[szB]) {
                Hash[szB] = ++ tot;
                reHash[Hash[szB]] = szB;
            }
            Nds[Hash[szA]].son = Hash[szB];
            Nds[Hash[szB]].par = Hash[szA];
            Union(Hash[szA], Hash[szB]);
        }
        scanf("%d", &M);
        for(int i = 0; i < M; i++) {
            cin >> szA >> szB;
            if(!Hash[szA] || !Hash[szB]) {
                puts("-1");
                continue;
            }
            int pa = Find(Hash[szA]), pb = Find(Hash[szB]);
            if(pa != pb) {
                puts("-1");
                continue;
            }
            int Index = get_lca(Hash[szA], Hash[szB]);
            cout << reHash[Index] << endl;
        }
    }
    return 0;
}

enter code here
0
import java.util.Scanner;
public class Main {
 public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    while(sc.hasNext()){
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a+b);
    }
}
}
0
public static main
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

bold italic bold&italic

  • a
  • b

github

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

0

???

0
echo $PATH
0
#include <stdio.h>
int main() {
    puts("hello, hiho");
    return 0;
}
0
LL gcd(LL a, LL b){
    if (b == 0)
        return a;
    return gcd(b, a%b);
}
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;
    }

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


转发分享