[問題] command format

作者: triumphant10 (yu12510)   2019-05-16 22:56:44
Language: C++
#include <iostream>
using namespace std;
long long int Mod(long long int a, long long int b, long long int c) {
if(b == 0) return 1;
if(b % 2 == 1) return a * Mod(a*a % c, b/2, c) % c;
else return Mod(a*a % c, b/2, c) % c;
}
int main(int argc, char *argv[]) {
long long int k, N, m;
cout<< "k: " ;
cin >> k ;
cout<< "N: ";
cin>> N ;
cout<< "m: ";
cin>> m ;
cout << k << "^" << N << " mod " << m << "=" << Mod(k, N, m) << endl;
return 0;
}
想問說怎麼用argc argv在規定的command format上跑?
這裡的command format是 /a.out k N m
爬了一些文,但還是看不懂該如何處理
所以想請問各位該如何解決?
謝謝
作者: RishYang (Rish)   2019-05-16 23:38:00
作者: TitanEric (泰坦)   2019-05-17 00:04:00
利用argv對空白切token 記得執行檔名是第一個
作者: RishYang (Rish)   2019-05-17 00:09:00
假設這樣執行: ./a.exe AA BB CCargc=4 *argv[0]="./a.exe" *argv[1] = "AA"*argv[2] = "BB" *argv[3] = "CC"
作者: dces4212 (flawless)   2019-05-20 04:51:00
搞懂指標這個想起來比較順

Links booklink

Contact Us: admin [ a t ] ucptt.com