跳到正文

休闲·娱乐

炸铃自动机

starowo约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
string g(const string& s) {
	string v=s;
	int pos=rand()%s.length();
	v[pos]=islower(v[pos])?toupper(v[pos]):tolower(v[pos]);
	pos=rand()%s.length();
	v[pos]=islower(v[pos])?toupper(v[pos]):tolower(v[pos]);
	return v;
}
int main(){
	srand(time(0));
	string S;
	cin>>S;
	if(S.size()<5){
		cout<<"too short";
		return 0;
	}
	unordered_set<string> seen;
	vector<string> vs;
	vs.push_back(S);
	while(vs.size()<9){
		string v=g(S);
		if(seen.insert(v).second) vs.push_back(v);
		if(seen.size()==2*S.length()) break;
	}
	for (const string& var:vs) cout<<"@"<<var<<" ";
	return 0;
}
原文