跳到正文

休闲·娱乐

关于码风~求大佬

sdywLYW约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年2月6日
收录
2026年2月6日
更新
2026年11月17日
篇幅
约 2 分钟

版本

  1. v1当前

代码码风还是比较有意义的。

求各路大佬的码风,也求大佬给我的码风提下建议。

我的码风:

随便拿一个代码展示一下:

本蒟蒻就拿hash为例。

C++
#include <iostream>
#include <string>
using namespace std;

typedef unsigned long long ULL;
#define rint register int
const int maxN = 2e7+1;
const ULL p = 131;
int n, m, l, mid, ans;
string s1,s2;
ULL *f = new ULL[maxN], *h1 = new ULL[maxN], *h2 = new ULL[maxN];

inline ULL get_hash(ULL* h,int l,int r)
  {return h[r] - h[l-1] * f[r-l+1];}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  cin >> n >> m >> s1 >> s2;
  s1 = "#" + s1; s2 = "#" + s2;
  f[1] = p; h1[1] = s1[1]; h2[1] = s2[1];
  for(rint i = 2;i <= n;++i)
    {f[i] = f[i-1] * p;h1[i] = h1[i-1] * p + s1[i];}
  for(rint i = 2;i <= m;++i)
    {f[i] = f[i-1] * p;h2[i] = h2[i-1] * p + s2[i];}
  for(mid = min(n,m);mid >= 1;--mid)
    if(get_hash(h1,1,mid)==get_hash(h2,m-mid+1,m)){
      ans = mid;break;
    }
  for(mid = min(n,m);mid >= 1;--mid)
    if(get_hash(h1,n-mid+1,n)==get_hash(h2,1,mid)){
      ans = max(ans,mid);break;}
  cout << ans;
  delete[] f; delete[] h1; delete[] h2;
  return 0;
}

求大佬评价一下。

我的理想码风:看着舒服,然后打比赛时敲代码的效率也快的。

原文