IaLWH @ 2024-08-10 14:24:27
rt,我马蜂太乱了,导致自己写完代码后自己就看不懂了
by Sun_pirf @ 2024-08-10 14:27:46
Dev-C++自带了,bdfs即可
by _MC2011_ @ 2024-08-10 14:27:52
//致谢:Junly_JYukio(背景优化)
//Libingyue2011(主体编辑)
//Believe_in_dreams(主要思路)
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
bitset<10010>bs;
int tb[300010],db[300010];
string tx;
int main() {
cerr<<" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
cerr<<"|C++格式调整机,请关闭你要调整的文件并保证此代码与你要调整的文件在一个文件夹里,且不要出现编译错误| \n";
cerr<<"| 注意事项:\n未加大括号的if,for,else,while与分支/循环体不在一行内可能会缩进错误 | \n";
cerr<<" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
cerr<<"请输出要调格式的文件名(不加后缀):\n";
string fl,pl;
cin>>fl,pl=fl;
fl+=".cpp",pl+=".txt";
cerr<<"处理中!!!\n";
freopen(fl.c_str(),"r",stdin);
freopen(pl.c_str(),"w",stdout);
string s;
int nober=0;
while(getline(cin,s)){//输入并且修正行内格式
cout<<s<<"\n";
int st=-1;
char d[30]="<>=+-*/^%!~()?.;,[]";
bool p=0;
while(s[0]=='\n') s.erase(0,1);
while(s[0]==9) s.erase(0,1);
while(s[0]==' ') s.erase(0,1);
if(s.size()==0) continue;
if(nober){
int pos=int(s.find("*/"));
if(pos!=-1) nober=0;
tx+=s;
continue;
}
bs=0;
int _pos=int(s.find("//"));//单行注释
if(_pos!=-1) for(int i=_pos;i<s.size();i++) bs[i]=1;
// cerr<<_pos<<"\n";
_pos=int(s.find("/*"));//多行注释
if(_pos!=-1 && !bs[_pos] && !bs[_pos+1]){
int pos_=int(s.find("*/"));
if(pos_==-1){
nober=1;
for(int i=_pos;i<s.size();i++) bs[i]=1;
}
else for(int i=_pos;i<=pos_+1;i++) bs[i]=1;
// cerr<<_pos<<" "<<pos_<<"\n";
}
for(int i=0;i<s.size();i++){
if(s[i]=='\"' || s[i]=='\'') p^=1;
if(!bs[i]) bs[i]=p;
}
for(int i=0;i<19;i++,st=-1)
while(s.find(d[i],st+1)!=-1){//删除符号左右的空格
int pos=s.find(d[i],st+1);
st=pos;
if(bs[i]) continue;
while(st>0 && s[st-1]==' ') s.erase(st-1,1),st--;
while(st<s.size()-1 && s[st+1]==' ') s.erase(st+1,1);
}
string t[30]={"if","for","else","while","struct","cin","cout","cerr"};
for(int i=0;i<8;i++,st=-1){//删除关键字前面的非换行
while(s.find(t[i],st+1)!=-1){
int pos=s.find(t[i],st+1);
st=pos;
if(bs[i]) continue;
if(st<s.size()-2 && s[st+1]==' ' && s[st+2]!=' ') s.erase(st+1,1);
if(i==0 && s[st-2]=='e' && s[st-3]=='s' && s[st-4]=='l' && s[st-5]=='e') continue;
if(st>1 && (s[st-1]!=')' && s[st-1]!='\n')) s.insert(st,1,'\n'),st++;
if(s[st-1]==')') s.insert(st,1,' '),st++;
}
}
if(s[0]==',') tx+=s;
else tx+=s+"\n";
}
string t[30]={"if","for","else","while","struct","cin","cout","cerr"};
Sleep(200);
cerr<<"已完成30%\n";
int st=-1,pos=-1;
while(tx.find("{",st+1)!=-1){//删掉大括号前的换行
st=tx.find("{",st+1);
while(st>0 && (tx[st-1]=='\n' || tx[st-1]==' ' || tx[st-1]==9)) tx.erase(st-1,1),st--;
if(tx[st-3]=='n' && tx[st-4]=='i' && tx[st-5]=='a' && tx[st-6]=='m') tx.insert(st,1,' '),st++;
}
Sleep(200);
cerr<<"已完成60%\n";
st=pos=-1;
while(tx.find("{",st+1)!=-1){//加tab
st=tx.find("{",st+1);
pos=tx.find("}",pos+1);
int pt=st;
while(tx.find("\n",pt+1)!=-1 && tx.find("\n",pt+1)<pos-1){
pt=tx.find("\n",pt+1);
tx.insert(pt+1,1,9),pos++;
}
//将st与pos的每一行加上tab
}
Sleep(300);
cerr<<"已完成100%\n";
freopen(fl.c_str(),"w",stdout);
cout<<tx;
cerr<<"欢迎使用C++格式调整机v4.0";
Sleep(100);
return 0;
}
/
#include <bits/stdc++.h> //求a+b的绝对值
using namespace std;
int main() {
int a , b ;
cin >> a >> b ;
//scanf("%d%d" , &a , &b );
if ( a + b > 0)
{
cout << a + b ;
/*printf("| %d + %d |=%d" , a , b , a+b );*/
}
else if(a + b < 0) cout << - a - b ;
else cout << 0 ;
return 0;
}
/
#include<bits/stdc++.h>//求a+b的绝对值
using namespace std;
int main() {
int a,b;
cin>>a>>b;
//scanf("%d%d" , &a , &b );
if(a+b>0){
cout<<a+b;
/*printf("| %d + %d |=%d" , a , b , a+b );*/
}
else if(a+b<0) cout<<-a-b;
else
cout<<0;
return 0;
}
我和同学自编的。
by _MC2011_ @ 2024-08-10 14:28:31
哦,我大号为 Libingyue2011。
直接 at 我大号吧。
by Libingyue2011 @ 2024-08-10 14:29:42
@IaLWH
by heyx0201 @ 2024-08-10 14:32:15
@MC2011 我可以用 C++ 格式调整机来调整 C++ 格式调整机的马蜂吗?(手动狗头
by TankYu @ 2024-08-10 14:33:55
使用VSCODE
by ln001 @ 2024-08-10 14:37:02
@IaLWH https://loj.ac/d/4301
by 11514zbs @ 2024-08-10 14:41:38
@Libingyue2011
我能引用一下你的文章吗?会注明作者的
by 11514zbs @ 2024-08-10 14:43:05
@MC2011 不对,是代码
by Libingyue2011 @ 2024-08-10 14:43:31
可以
@11514zbs
你要引用哪篇。