求助,输出奇怪
查看原帖
求助,输出奇怪
540872
z_yk楼主2023/7/6 21:13

代码量有点大,做成了模拟,应该是好理解的罢(悲

#include<iostream>
#include<string>
#include<cstring>

using namespace std;

short p1;
short p2;
short p3;
string str;
int ccnt;

string son[10010];
int divstr() {
	int cnt=1;
	for(int i=0; i<str.length(); i++) {
		if(str[i]!='-') {
			son[cnt][i]=str[i];
		} else {
			cnt++;
		}
	}
	return cnt;
}

bool ce(char a,char b) {
	if(a<b)return true;
	return false;
}

void output() {
	for(int i=1; i<=ccnt; i++) {
		cout<<son[i];
		if(ce(son[i][son[i].length()-1],son[i+1][son[i+1][0]])) {
			if(p1==1) {
				if(p3==1) {
					for(int j=0; j<son[i].length(); j++) {
						for(int k=1; k<=p2; k++) {
							if(65<=son[j][k]<97)cout<<char(son[j][k]+32);
							else cout<<son[j][k];
						}
					}
				} else {
					char cccnt[10010];
					int tmp=0;
					for(int j=0; j<son[i].length(); j++) {
						for(int k=1; k<=p2; k++) {
							if(65<=son[j][k]<97)cccnt[tmp]=char(son[j][k]+32);
							else cccnt[tmp]=son[j][k];
							tmp++;
						}
					}
					for(int j=tmp; j>=0; j--)cout<<cccnt[j];
				}
			} else {
				if(p3==1) {
					for(int j=0; j<son[i].length(); j++) {
						for(int k=1; k<=p2; k++) {
							if(65<=son[j][k]<97)cout<<char(son[j][k]+32);
							else cout<<son[j][k];
						}
					}
				} else {
					char cccnt[10010];
					int tmp=0;
					for(int j=0; j<son[i].length(); j++) {
						for(int k=1; k<=p2; k++) {
							if(65<=son[j][k]<97)cccnt[tmp]=char(son[j][k]+32);
							else cccnt[tmp]=son[j][k];
							tmp++;
						}
					}
					for(int j=tmp; j>=0; j--)cout<<cccnt[j];
				}
			}
		} else cout<<"-"<<son[i];
	}
}

int main() {
	cin>>p1>>p2>>p3>>str;
	ccnt=divstr();//初始化并记录子串个数
	output();//输出 
	return 0;
}
2023/7/6 21:13
加载中...