當前位置:首頁 » 編程語言 » java字元串演算法

java字元串演算法

發布時間: 2022-02-21 11:35:39

Ⅰ 求java演算法:這里有A,B,C,D,E五個字元串,求出五個字元串的所有任意組合(五個字元串可以不同時出現)

有些人的用復制數列,演算法低效、粗野浪費。

給你個、 高效、簡潔而且泛型通用的全組合:
public class Test{
public static void main(String[] args) {
String[] a = { "A", "B", "C", "D", "E" };
for(int i=1;i<=a.length;i++){
System.out.println(a.length+"選"+i);
String[] res=new String[i];
combine(a,0,res,0);
}
}
final static public void combine(final Object a[], final int a_pos,final Object rs[], final int rs_pos)
{
if(rs_pos>=rs.length){
for(int i=0;i<rs.length;i++) System.out.print(rs[i]+" ");
System.out.println();
}else for(int ap=a_pos; ap<a.length; ap++){
rs[rs_pos]=a[ap]; combine(a,ap+1,rs,rs_pos+1);
}
}
}
=======
5選1
A
B
C
D
E
5選2
A B
A C
A D
A E
B C
B D
B E
C D
C E
D E
5選3
A B C
A B D
A B E
A C D
A C E
A D E
B C D
B C E
B D E
C D E
5選4
A B C D
A B C E
A B D E
A C D E
B C D E
5選5
A B C D E

Ⅱ 我想實現一個演算法,用JAVA來實現,比如有一串字元串,abcdefghijk123456789這樣隨機生成的數據生成兩位的

I can only C++

#include<stdio.h>

const int mod=10007;
int getCheck(char s[])
{
int i,check=0;
for(i=0;s[i];i++)
{
check+=(int)s[i]*(int)s[i]%mod;
}
return check%mod%100;
}
void main( void )
{
char s[100]="abcdefghijk123456789";
//you can genaration a check number
//when you get a string you can genaration another check number and compare it to the origonal number.
printf("%02d\n",getCheck(s));
}

Ⅲ java有沒有加密字元串為一串數字的演算法

沒有 用的多的就MD5 sha1 aes
你把它換成16進制吧 那樣人就看不懂了 而且還是數字

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:541
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:828
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:531
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:713
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:633
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:946
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:204
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:62
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:756
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:659