AI代码的特征(全)
2025-10-18 19:06:20
发布于:浙江
声明:这篇帖子包含了较多其他同类帖的成分,此处进行特别鸣谢
一、代码格式类
1.运算符之间多空格,如:
i += 1;
h = i + n;
if(s == 7) break;
2.常用以下格式:
if(x)
{
//TODO
}
for(int i=1;i<=x;i++)
{
//TODO
}
而不是:
if(x){
//TODO
}
for(int i=1;i<=x;i++){
//TODO
}
3、经常无理由换行:
if(x==1){
//TODO
}
cout<<"3.1415926";
二、代码写法类
1、不用万能头,如:
#include<stdio.h>
#include<iostream>
2、多注释,但不是给自己看的,如:
int s=30; //定义
s+=rand()%10; //变成彩票,用随机数
if(s==30) cout<<"中"; //如果前后一样,就中
else cout<<"oh no"; //否则不中
3、多用vector,如:
vector<int>asdasd;
//TODO
4、无命名空间,如:
#include <iostream>
int main(){
std:://TODO
}
5、多std::,如:
std::cout<<114514<<endl;
6、无return 0;
#include <iostream>
int main(){
std:://TODO
}
7、宁死不用define
#include <iostream>
typedef long long ll
int main(){
std:://TODO
}
8、多用奇怪的符号
(a>b)?a:b;
us>>g;
9、用函数包装代码,如:
int add(int x,int y){
//TODO
}
int dfs(int a,int b){
//TODO
}
int main(){
add(n,m);
dfs(1,1);
}
三、变量类
1、变量长,如:
struct appelisverygoodforeey{
int numbersize;
string countapple;
};
2、多用大写与下划线,如:
int Ques_gpt;
char Ferry_bin;
long long tuNucnt__dd;
3、多用常量,如:
const int MOD=INT_MAX-1;
示例 AI代码:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
int n, k, p;
cin >> n >> k >> p;
vector<double> h(n);
for (int i = 0; i < n; ++i)
{
cin >> h[i];
}
// 将1号城市的水位单独处理
double h1 = h[0];
vector<double> others;
for (int i = 1; i < n; ++i)
{
others.push_back(h[i]);
}
// 将其他城市按水位从高到低排序
sort(others.rbegin(), others.rend());
// 贪心算法:每次选择最高水位城市与1号城市连通
for (double city : others)
{
if (k <= 0) break;
if (city > h1)
{
h1 = (h1 + city) / 2.0;
k--;
}
}
// 设置输出精度
cout << fixed << setprecision(p);
cout << h1 << endl;
}
最后,祝点赞的人幸福每一天!
全部评论 5
#typedef ll long long
应改为
typedef long long ll
4天前 来自 江西
0AI爱加:
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);5天前 来自 浙江
0AI不写“cout.tie(0)”
4天前 来自 浙江
0
现在AI聪明了,用命名空间了
5天前 来自 浙江
0还更新吗
5天前 来自 浙江
0会
4天前 来自 浙江
0啥时候更新
4天前 来自 浙江
0马上
4天前 来自 浙江
0
这里空空如也2025-09-30 来自 浙江
0
有帮助,赞一个