当前位置:网站首页>Full arrangement of numbers (digital password dictionary)

Full arrangement of numbers (digital password dictionary)

2022-06-12 09:08:00 Record dada I

Digital password dictionary

Number selection space :0-9
do n A complete arrangement of digits

Console output :

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
    
	int n;
	cin>>n;
	int num=1;

	for(int i =1; i<n; i++) {
    
		num=num*10;// Calculate the start bit 
	}
	int sum=num*10-1;// Calculation end bit 

	for(int i =0; i<=sum; i++) {
    
		cout<<setw(n)<<setfill('0')<<i<<endl;// common n position , The front is not enough to fill zero  , single quote  
	}
	return 0;
}

Write it to the file :

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
    
	int n;
	cin>>n;
	int num=1;
	
	ofstream write;// Define variables written to the file 
	write.open("password.txt");// Indicates that you want to output the content to “password.txt" In this document   If you don't have this file , This file will be created automatically 
	for(int i =1; i<n; i++) {
    
		num=num*10;// Calculate the start bit 
	}
	int sum=num*10-1;// Calculation end bit 
	int j=0;
	for(int i =0; i<=sum; i++) {
    
		write<<setw(n)<<setfill('0')<<i<<endl;// common n position , The front is not enough to fill zero  , single quote  
		j++;// Count the number of generated passwords  
	}
	write.close();// Close input stream 
	 
	cout<<" Output complete , Generate password altogether :"<<j; 
	return 0;
}

原网站

版权声明
本文为[Record dada I]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010531527124.html