導航:首頁 > 源碼編譯 > 模乘cios演算法源碼

模乘cios演算法源碼

發布時間:2023-03-24 13:56:14

⑴ 兩道編程演算法題(兩圖一道),題目如下,可以給出演算法思路或者源代碼,源代碼最好是C語言的

就會個第一題(因為第一題上已經給出了大致思路)

思路:用map容器(它的內部數據結構是一顆紅黑樹,查找和插入數據速度非常快)
map<int,st>a;//key(int):設置為1~n的數;value(st):設置為key的前驅和後繼;

這樣一來就可以像鏈錶快速插入數據,又可以像數組隨機訪問元素(key,就相當於數組的下標)

下面是代碼和運行截圖;

看代碼前建議先了解一下map容器的具體用法;

#include<iostream>

#include<map>

#include<vector>

using namespace std;

struct st{//兩個成員變數用來儲存前驅和後繼

int left;//0

int right;//1

st()

{

left=0;

right=0;

}

};

void input(map<int,st> &a)//輸出

{

st t;

int s=0;

map<int,st>::iterator it;//迭代器(指針)

for(it=a.begin();it!=a.end();it++)//循環迭代

{

t=it->second;

if(t.left==0)//左邊等於0,說明該數是第一個數

{

s=it->first;//記錄key

break;

}

}

t=a[s];

cout<<s<<" ";

while(t.right!=0)//循環找當前數的右邊的數(右邊的為0,就說明該數是最後一個數)

{

cout<<t.right<<" ";

t=a[t.right];

}

}

int main()

{

st t,t_i,t_x,t_k,s;

map<int,st>a;

map<int,st>::iterator it;

int n,x,p,x_l,x_r;

cin>>n;

for(int i=1;i<=n;i++)//map容器賦初值(i,t)

//i:(key)下標;t:(value)結構體變數

{

a.insert(make_pair(i,t));

}

for(int i=2;i<=n;i++)

{

cin>>x>>p;

if(p==0)//x的左邊插入i

{

t=a[x];

if(t.left==0)//x的左邊沒有數

{

t_x.left=i;

t_i.right=x;

a[x]=t_x;

a[i]=t_i;

}

else//x的左邊有數

{

int x_left;

t_x=a[x];

x_left=t_x.left;

t_k=a[x_left];

t_i.right=x;

t_i.left=t_x.left;

t_k.right=i;

t_x.left=i;

a[x]=t_x;

a[i]=t_i;

a[x_left]=t_k;

}

}

else//x的右邊插入i

{

t=a[x];

if(t.right==0)//x的右邊沒有數

{

t_x.right=i;

t_i.left=x;

a[x]=t_x;

a[i]=t_i;

}

else//x的左邊有數

{

int x_right;

t_x=a[x];

x_right=t_x.right;

t_k=a[x_right];

t_i.left=x;

t_i.right=t_x.right;

t_k.left=i;

t_x.right=i;

a[x]=t_x;

a[i]=t_i;

a[x_right]=t_k;

}

}

}

for(it=a.begin();it!=a.end();it++)//循環迭代列印各個數之間的關系

{

cout<<it->first<<" ";

cout<<"左邊:";

cout<<it->second.left<<" ";

cout<<"右邊:";

cout<<it->second.right<<endl;

}

input(a);//列印序列

return 0;

}

/*

4

1 0

2 1

1 0

2 3 4 1

*/

⑵ 關於模乘的演算法

RSA演算法中用到的大數運算

C. 大數的運算
1. 大數的運算原理
RSA演算法依賴於大數的運算,目前主流RSA演算法都建立在512位到1024位的大數運算之

上,所以我們首先需要掌握大數(比如1024位)的運算原理。
大多數的編譯器只能支持到32位(或64位)的整數運算,即我們在運算中所使用的

整數必須小於等於32位,即0xFFFFFFFF,這遠遠達不到RSA的需要,於是需要專門建

立大數運算庫,來解決這一問題。
最簡單的辦法是將大數當作字元串進行處理,也就是將大數用10進制字元數組進行

表示,然後模擬人們手工進行「豎式計算」的過程編寫其加減乘除函數。但是這樣

做效率很低。當然其優點是演算法符合人們的日常習慣,易於理解。
另一種思路是將大數當作一個二進制流進行處理,使用各種移位和邏輯操作來進行

加減乘除運算,但是這樣做代碼設計非常復雜,可讀性很低,難以理解也難以調試


這里我們採用了一種介於兩者之間虛臘的思路:將大數看作一個N進制數組,對於目前的

32位系統而言,N可以取2的32次方,即0x100000000,假如將一個1024位的大數轉化

成0x10000000進制,它就變成了32位,而每一位的取值范圍是0-0xFFFFFFFF。我們

正好可以用一個無符號長整數來表罩侍示這一數值。所以1024位的大數就是一個有32個

元素的unsigned long數組。而且0x100000000進制的數組排列與2進制流對於計算機

來說,實際上是一回事,但是我們完全可以針對unsigned long數組進行「豎式計算

」,而循環規模被降低到物譽吵了32次之內,並且演算法很容易理解。
但考慮到乘法和除法,都要進行擴展才能進行快速的計算(如果把除法變減法而不

擴展,速度將慢的無法忍受)。所以我們將N取2的16次方的,即0xFFFF。每一位用

unsigned short來表示,當進行乘除運算時,將short擴展成long,這是編譯器所支

持的,所以運算起來,比較快。

⑶ 用C或者C++語言實現這些多精度模乘演算法。包括:32bit*32bit,64bit*64bit,128bit*128bit,256bit*256bit

把我的高精度模版 貼一下, 完全可以實現 256bit
。。。。。。。。。。。殲早。。。。氏盯雀。。。。。。。。。。。。。。

#include<iostream>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;
class BigNum;
istream& operator>>(istream&, BigNum&);
ostream& operator<<(ostream&, BigNum&);
#define MAXN 9999
#define MAXSIZE 20000 //這是大數的位數,一個數組元素存儲四位,那麼一共就是20000*4 位數。
#define DLEN 4
class BigNum
{
public:
int a[MAXSIZE]; //數組模擬大數,一個數組元素存儲四位數。
int len;
public:
BigNum(){len = 1;memset(a,0,sizeof(a));}
BigNum(const int);
BigNum(const char*);
BigNum(const BigNum &);
BigNum &operator=(const BigNum &);
friend istream& operator>>(istream&, BigNum&);
friend ostream& operator<<(ostream&, BigNum&);
BigNum operator*(const BigNum &) const;

};

//輸入重載
istream& operator>>(istream & in, BigNum & b)
{
char ch[MAXSIZE*4];
int i = -1;
memset(b.a,0,sizeof(b.a));
in>>ch;
int l=strlen(ch);
int count=0,sum=0;
for(i=l-1;i>=0;)
{
sum = 0;
int t=1;
for(int j=0;j<4&&i>=0;j++,i--,t*=10)
{
sum+=(ch[i]-'0')*t;
}
b.a[count]=sum;
count++;
}
b.len =count++;
return in;

}

//輸出重載則粗。
ostream& operator<<(ostream& out, BigNum& b)
{
int i;
cout << b.a[b.len - 1];
for(i = b.len - 2 ; i >= 0 ; i--)
{
cout.width(DLEN);
cout.fill('0');
cout << b.a[i];
}
return out;
}

//下面是構造函數。
BigNum::BigNum(const int b)
{
int c,d = b;
len = 0;
memset(a,0,sizeof(a));
while(d > MAXN)
{
c = d - (d / (MAXN + 1)) * (MAXN + 1);
d = d / (MAXN + 1); a[len++] = c;
}
a[len++] = d;
}
BigNum::BigNum(const char*s)
{
int t,k,index,l;
memset(a,0,sizeof(a));
l=strlen(s);
len=l/DLEN;
if(l%DLEN)len++;
index=0;
for(int i=l-1;i>=0;i-=DLEN)
{
t=0;k=i-DLEN+1;
if(k<0)k=0;
for(int j=k;j<=i;j++)
t=t*10+s[j]-'0';
a[index++]=t;
}
}
BigNum::BigNum(const BigNum & T) : len(T.len)
{
int i;
memset(a,0,sizeof(a));
for(i = 0 ; i < len ; i++) a[i] = T.a[i];
}
////////////////////////////////////////////////

//賦值重載。
BigNum & BigNum::operator=(const BigNum & n)
{
len = n.len;
memset(a,0,sizeof(a));
for(int i = 0 ; i < len ; i++)
a[i] = n.a[i];
return *this;
}

//乘法重載。
BigNum BigNum::operator*(const BigNum & T) const
{
BigNum ret;
int i,j,up;
int temp,temp1;
for(i = 0 ; i < len ; i++)
{
up = 0;
for(j = 0 ; j < T.len ; j++)
{
temp = a[i] * T.a[j] + ret.a[i + j] + up;
if(temp > MAXN)
{
temp1 = temp - temp / (MAXN + 1) * (MAXN + 1);
up = temp / (MAXN + 1);
ret.a[i + j] = temp1;
}
else
{
up = 0;
ret.a[i + j] = temp;
}
}
if(up != 0)
ret.a[i + j] = up;
}
ret.len = i + j;
while(ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len--;
return ret;
}

/*****************************************/

int main()
{
BigNum a,b,c;
cin>>a>>b; //輸入大數。
c=a*b; //計算a*b
cout<<c<<endl; //輸出c
return 0;
}

⑷ GitHub 上有哪些完整的 iOS-App 源碼值得參考

1. Coding iOS 客戶端

Coding官方客戶端. 筆者強烈推薦的值得學習的完整APP.
GitHub - Coding/Coding-iOS: Coding iOS 客戶端源代碼
2. OSCHINA 的 iPhone 客戶端
開源中國的iPhone客戶端源碼
https://git.oschina.net/oschina/iphone-app
3. Git@OSC
Git@OSC iPhone 客戶端,方便用戶查看Git@OSC的項目以及簡單的操作issue等
oschina / git-osc-iphone
4. Firefox for iOS
GitHub - mozilla/firefox-ios: Firefox for iOS
5. zulip-ios
Dropbox收購公司內部社交服務商Zulip,然後全部開源,這是iOS App
GitHub - zulip/zulip-ios: Zulip iOS app
6. iOSSF
SegmentFault官方App
GitHub - gaosboy/iOSSF: SegmentFault官方App
7. iReddit
Reddit iPhone客戶端
GitHub - reddit/iReddit: The iReddit iPhone app
8. Monkey
GitHub第三方iOS客戶端
GitHub - coderyi/Monkey: Monkey is a GitHub third party client for iOS,to show the rank of coders and repositories.
9. Watch
Dribbble第三方客戶端
GitHub - tuesda/Watch: A project which demonstrate how to develop a custom client on android for dribbble.com
10. Voice2Note
懶人筆記iOS客戶端
GitHub - liaojinxing/Voice2Note: 懶人筆記iOS客戶端
11. RSSRead
「已閱」(iOS上開源RSS新聞閱讀器)
GitHub - ming1016/RSSRead: 「已閱」(iOS上開源RSS新聞閱讀器),有興趣?那就Pull Requests吧
12. BeeFancy
BeeFancy仿Fancy官方APP的WIREFRAME,基於BeeFramework
GitHub - BeeFramework/BeeFancy: 仿Fancy官方APP的WIREFRAME,基於BeeFramework
13. SXNews
模仿網易新聞做的精仿網易新聞
GitHub - dsxNiubility/SXNews: High imitation Neteasy News. (include list,detail,photoset,weather,feedback)
14. Doppio
尋找最近的星巴克
GitHub - chroman/Doppio: An open source iOS app to find the nearest Starbucks store using NSURLSession, AFNetworking 2.0, Mantle and Starbucks private API.
15. Anypic
類似於Instagram的一款App
GitHub - ParsePlatform/Anypic: An open source mobile and web app that lets users share photos similar to Instagram
16. 豆瓣相冊
Slowslab iOS應用 豆瓣相冊 精選集 開源項目
GitHub - TonnyTao/DoubanAlbum: Slowslab iOS應用 豆瓣相冊 精選集 開源項目,僅供學習參考
17. ChatSecure-iOS
Objective-C寫的XMPP聊天應用
GitHub - ChatSecure/ChatSecure-iOS: ChatSecure is a free and open source encrypted chat client for iPhone and Android that supports OTR encryption over XMPP.
18. NotificationChat
Objective-C寫的完整的聊天應用
GitHub - relatedcode/EncryptedChat: This is a full native iPhone app to create realtime, text based group or private chat with Parse and Firebase.
19. FakeZhihuDaily
仿知乎日報iOS客戶端
GitHub - gnou/FakeZhihuDaily: 仿知乎日報iOS客戶端
20. ruby-china-for-ios
RubyChina官方客戶端
GitHub - ruby-china/ruby-china-for-ios: Ruby China client for iOS
21. Meizi
豆瓣妹子圖iOS客戶端
GitHub - Sunnyyoung/Meizi: 豆瓣妹子圖iOS客戶端
22. PlainReader
一款 iOS(iPhone + iPad) 新聞類客戶端,內容抓取自http://cnBeta.com
PlainReader/PlainReader at master · guojiubo/PlainReader · GitHub
23. iOS-2048
用Objective-C實現的2048游戲
GitHub - austinzheng/iOS-2048: iOS drop-in library presenting a 2048-style game
24. ECMobile_iOS
基於ECShop的手機商城客戶端
GitHub - GeekZooStudio/ECMobile_iOS: 基於ECShop的手機商城客戶端
25. wikipedia-ios
維基網路官方App, 已上架
GitHub - wikimedia/wikipedia-ios: The official Wikipedia iOS app.
26. Sol
漂亮的扁平風格的天氣App
GitHub - comyarzaheri/Sol: Sol° beautifully displays weather information so you can plan your day accordingly. Check the weather in your current location or any city around the world. Implemented in Objective-C.

閱讀全文

與模乘cios演算法源碼相關的資料

熱點內容
小仙兒有聲小說 瀏覽:182
罪孽2電影泰國版 瀏覽:757
美國電影蛇妖 瀏覽:684
滿青十大酷型電影 瀏覽:434
dayz進不了伺服器怎麼辦 瀏覽:386
安卓usbdac怎麼使用 瀏覽:939
法國小女生電影 瀏覽:308
反編譯本地運算游戲 瀏覽:566
阿里雲伺服器被攻擊了多久恢復 瀏覽:293
我的孝順女兒電影 瀏覽:597
翠微居txt下載 瀏覽:394
tom快播 瀏覽:662
換硬幣演算法遞歸 瀏覽:122
四級電影推薦 瀏覽:847
女主手臂處有射精管理局臂章的電影 瀏覽:328
從哪找韓國電影 瀏覽:313
pdf轉換成ppt如何轉換 瀏覽:146
國內越南戰爭的電影 瀏覽:246
台灣好看的倫理電影 瀏覽:525
外遇的妻子2李采潭 瀏覽:954