#2283: 執行時發生錯誤 (SIGSEGV)(11)!!


chi (chi)

學校 : 不指定學校
編號 : 7433
來源 : [219.84.153.240]
最後登入時間 :
2011-03-13 00:17:15
a020. 身分證檢驗 | From: [219.84.153.240] | 發表日期 : 2009-08-21 23:52

執行時發生錯誤 (SIGSEGV)(11)!!
Segmentation fault, an address reference boundary error.(記憶體區段錯誤)
可能原因為:
* 通常為使用超過陣列範圍
* 指標指向不正確位址!
* 陣列初始化不正確!
* 嘗試在執行時期定義陣列長度!
sh: line 1: 17683 程式記憶體區段錯誤  
 

 

 

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int i, j, sum;
    char *_p[] = {"10", "11", "12", "13", "14", "15", "16", "17", "34", "18"
            , "19", "20", "21", "22", "35", "23", "24", "25", "26", "27", "28"
            , "29", "32", "30", "31", "33"};
    char _id[10] = {'\0'};
    
    while (cin >> _id) {
        j = _id[0] - 'A';
        sum = (*_p[j] - '0') + ((*(_p[j]+1)-'0')*9);
        sum += (_id[9]-'0');
        i = 0;
        while(++i<9) {
            j = (_id[i]-'0')*(9-i);
            sum += j;
        }
        if ((sum%10)) {
            cout << "fake";
        } else {
            cout << "real";
        }
        cout <<endl;
    }
    return 0;
}

 
#2284: Re:執行時發生錯誤 (SIGSEGV)(11)!!


chi (chi)

學校 : 不指定學校
編號 : 7433
來源 : [219.84.153.240]
最後登入時間 :
2011-03-13 00:17:15
a020. 身分證檢驗 | From: [219.84.153.240] | 發表日期 : 2009-08-21 23:57

執行時發生錯誤 (SIGSEGV)(11)!!
Segmentation fault, an address reference boundary error.(記憶體區段錯誤)
可能原因為:
* 通常為使用超過陣列範圍
* 指標指向不正確位址!
* 陣列初始化不正確!
* 嘗試在執行時期定義陣列長度!
sh: line 1: 17683 程式記憶體區段錯誤  
 

 

 

#include
#include

using namespace std;

int main(int argc, char *argv[])
{
    int i, j, sum;
    char *_p[] = {"10", "11", "12", "13", "14", "15", "16", "17", "34", "18"
            , "19", "20", "21", "22", "35", "23", "24", "25", "26", "27", "28"
            , "29", "32", "30", "31", "33"};
    char _id[10] = {'\0'};
    
    while (cin >> _id) {
        j = _id[0] - 'A';
        sum = (*_p[j] - '0') + ((*(_p[j]+1)-'0')*9);
        sum += (_id[9]-'0');
        i = 0;
        while(++i<9) {
            j = (_id[i]-'0')*(9-i);
            sum += j;
        }
        if ((sum%10)) {
            cout << "fake";
        } else {
            cout << "real";
        }
        cout <
    }
    return 0;
}

======

自問自答

 

用11

 
ZeroJudge Forum