Пример #1
0
int
main(int argc, char** argv)
{
    FILE *fin  = fopen("gift1.in", "r");
    FILE *fout = fopen("gift1.out", "w");
    unsigned int np = 0; //2 <= NP <= 10
    unsigned int i=0, j = 0;
    Person_S *giver, *receiver;
    char name[NAME_MAX_LEN+1] = {0};
    int money = 0, nums = 0;

    //line 1 NP
    fscanf(fin, "%u\n", &np);
    /*printf("%d\n", np);//testing*/
    s_group = malloc(np*sizeof(Person_S));

    //line 2..NP+1  Each line contains the name of a group member
    for(i=0; i<np; i++)
    {
        fscanf(fin, "%s\n", s_group[i].name);
        s_group[i].money = 0;
        /*printf("%s\n", s_group[i].name);*/
    }

    //line NP+2..EOF 
    /*NP groups of lines organized like this:
    The first line in the group tells the person's name who will be giving gifts.
    The second line in the group contains two numbers: The initial amount of money (in the range 0..2000) to be divided up into gifts by the giver and then the number of people to whom the giver will give gifts, NGi (0 ≤ NGi ≤ NP-1).
    If NGi is nonzero, each of the next NGi lines lists the the name of a recipient of a gift. 
    */
    for(i=0; i<np; i++)
    {
        fscanf(fin, "%s\n", name);
        giver = FindPerson(np, (const char*)name);
        fscanf(fin, "%d %d\n", &money, &nums); 
        /*giver->money += money;*/
        for (j=0; j<nums; j++)
        {
            fscanf(fin, "%s\n", name); 
            receiver = FindPerson(np, (const char*)name);
            GiveMoney(giver, receiver, money/nums);
        }
    }

    //Output data
    for(i=0; i<np; i++)
    {
        fprintf(fout, "%s %d\n", s_group[i].name, s_group[i].money);
    }

    free(s_group);
    fclose(fin);
    fclose(fout);
    return 0;
}
Пример #2
0
LRESULT CALLBACK Fq4EditorWindow::OnCommand( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    int wmId = LOWORD( wParam );
    switch ( wmId )
    {
    case IDM_KINGS:
        {
            int count = GiveTeam( m_kingDatas );
            std::wstring&& message = LogTeamResult( count, m_kingDatas.size() );
            MessageBox( hWnd, message.c_str(), L"國王們", MB_OK );
        }
        break;

    case IDM_FOREST:
        {
            int count = GiveTeam( m_forestDatas );
            std::wstring&& message = LogTeamResult( count, m_forestDatas.size() );
            MessageBox( hWnd, message.c_str(), L"森林國 雷斯達", MB_OK );
        }
        break;

    case IDM_ELF:
        {
            int count = GiveTeam( m_elfDatas );
            std::wstring&& message = LogTeamResult( count, m_elfDatas.size() );
            MessageBox( hWnd, message.c_str(), L"精靈國 薩內多", MB_OK );
        }
        break;

    case IDM_MINE:
        {
            int count = GiveTeam( m_mineDatas );
            std::wstring&& message = LogTeamResult( count, m_mineDatas.size() );
            MessageBox( hWnd, message.c_str(), L"礦山國 格林斯", MB_OK );
        }
        break;

    case IDM_SEA:
        {
            int count = GiveTeam( m_seaDatas );
            std::wstring&& message = LogTeamResult( count, m_seaDatas.size() );
            MessageBox( hWnd, message.c_str(), L"海盜國 慕尼頓", MB_OK );
        }
        break;

    case IDM_PLAIN_MAGICIAN:
        {
           int count = GiveTeam( m_plainMagicianDatas );
           std::wstring&& message = LogTeamResult( count, m_plainMagicianDatas.size() );
           MessageBox( hWnd, message.c_str(), L" 平原國 休利亞(魔法軍團)", MB_OK );
        }
        break;

    case IDM_PLAIN_KNIGHT:
        {
            int count = GiveTeam( m_plainKnightDatas );
            std::wstring&& message = LogTeamResult( count, m_plainKnightDatas.size() );
            MessageBox( hWnd, message.c_str(), L"平原國 休利亞(騎士軍團)", MB_OK );
        }
        break;

    case IDM_ITEM:
        {
            GiveItem();
            MessageBox( hWnd, L"所有道具 +10", L"ITEM", MB_OK );
        }
        break;

    case IDM_MONEY:
        {
            GiveMoney();
            MessageBox( hWnd, L"獲得 $10000", L"MONEY", MB_OK );
        }
        break;

    case IDM_TIRED:
        {
            ReleaseFatigue();
        }
    break;

    default:
        return EditorWindow::OnCommand( hWnd, message, wParam, lParam );
    }

    return 0;
}