思路
因为有很多的相似部分不妨用define
定义一下, 会很好.
Code
#include <bits/stdc++.h>
using namespace std;
#define MAXN 32005
#define F(i, a, b) for(int i=a; i<=b;i++)
#define Fd(i, a, b) for(int i=a;i>=b;i--)
#define out(x) buf[cnt++] = (x)
#define LOP F(k, 1, p2){\
if(p1 == 1){\
if(j>='A' && j<='Z'){\
cout<<tolower((char)j);\
}else{\
out(char(j));\
}\
}else if(p1 == 2){\
if(j>='a' && j<='z'){\
out(toupper((char)j));\
}else{\
out(char(j));\
}\
}else if(p1 == 3){\
out('*');\
}\
}
char buf[MAXN] = {};
int cnt= 0;
int main(){
int p1, p2, p3; cin>>p1>>p2>>p3;
string s; cin>>s;
s = "$"+s;
int len = s.length();
F(i, 1, len){
if(s[i] == '-'){
if(i != len){
if(s[i-1] < s[i+1]
&&
(
(isdigit(s[i-1]) && isdigit(s[i+1]))||
(isalpha(s[i-1]) && isalpha(s[i+1]))
)
){
if(p3 == 2){
Fd(j, s[i+1]-1, s[i-1]+1){
LOP
}
}else if(p3 == 1){
F(j, s[i-1]+1, s[i+1]-1){
LOP
}
}
}else{
out(s[i]);
}
}else{
out(s[i]);
}
}else{
out(s[i]);
}
}
cout<<buf<<endl;
}
标签:NOIP,变换,len,else,LOP,字串,&&,define,out
From: https://www.cnblogs.com/augpath/p/16862270.html