| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 374577 人关注过本帖, 11 人收藏
标题:入境随俗:《编程论坛生存手册》
只看楼主 加入收藏
kingoftheworld
Rank: 1
来 自:湖北
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-7-5
收藏
得分:0 
简单
没用main函数
2008-07-05 15:31
aliciersky
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-7-5
收藏
得分:0 
支持了
  我对这些都不怎么熟悉 主要是来学习的
2008-07-05 20:07
sxby_01
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2008-7-5
收藏
得分:0 
回复 1# 静夜思 的帖子
谢谢
2008-07-06 00:07
飞猪设计
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-7-6
收藏
得分:0 
   .......
2008-07-06 03:41
yang5312775
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-7-6
收藏
得分:0 
将支持进行到底
新手初来咋到,请大家支持支持
2008-07-06 15:28
龙龙爱着徐琼
Rank: 1
来 自:石家庄
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-7-6
收藏
得分:0 
错哪了?
#include <stdio.h>
#include <conio.h>
#include <bios.h>

#define NULL 0
typedef struct menu
{
    int ID;
    int x;
    int y;
    int active;
    char content[20];
    struct menu *pSubMenu;
    int n_SubMenu;
}MENU;
#define FILE 1
#define EDIT 2
#define SORT 3
#define FILTER 4
#define HELP 5
#define FILE_NEW 11
#define FILE_OPEN 12
#define FILE_SAVE 13
#define FILE_SAVEAS 14
#define FILE_CLOSE 15
#define FILE_EXIT 16
#define EDIT_ADD 21
#define EDIT_DEL 22
#define EDIT_MOD 23
#define SORT_NUM 31
#define SORT_NAME 32
#define FILTER_NUM 41
#define FILTER_NAME 42
#define FILTER_NEW 43
#define HELP_HELP 51
#define HELP_ABOUT 52
MENU FileSub[6]={
        {FILE_NEW,1,2,1,"New",NULL,0},
        {FILE_OPEN,1,3,0,"Open",NULL,0},
        {FILE_SAVE,1,4,0,"Save",NULL,0},
        {FILE_SAVEAS,1,5,0,"Save As",NULL,0},
        {FILE_CLOSE,1,6,0,"Close",NULL,0},
        {FILE_EXIT,1,7,0,"Exit",NULL,0}
        };
MENU EditSub[3]={
        {EDIT_ADD,15,2,1,"Add",NULL,0},
        {EDIT_DEL,15,3,0,"Delete",NULL,0},
        {EDIT_MOD,15,4,0,"Modify",NULL,0}
        };
MENU SortSub[2]={
        {SORT_NUM,30,2,1,"Number",NULL,0},
        {SORT_NAME,30,3,0,"Name",NULL,0}
        };
MENU FilterSub[3]={
        {FILTER_NUM,45,2,1,"Number",NULL,0},
        {FILTER_NAME,45,3,0,"Name",NULL,0},
        {FILTER_NEW,45,4,0,"New",NULL,0}
        };
MENU HelpSub[2]={
        {HELP_HELP,60,2,1,"Help",NULL,0},
        {HELP_ABOUT,60,3,0,"About",NULL,0}
        };
MENU MainMenu[5]={
        {FILE,1,1,0,"File",FileSub,6},
        {EDIT,15,1,0,"Edit",EditSub,3},
        {SORT,30,1,0,"Sort",SortSub,2},
        {FILTER,45,1,0,"Fileter",FilterSub,3},
        {HELP,60,1,0,"Help",HelpSub,2}
        };
void MenuDraw(MENU *pMenu,int n)
{
    window(1,1,80,25);
    for(;n>0;n--)
    {
        textbackground(pMenu->active?BLUE:WHITE);
        textcolor(RED);
        gotoxy(pMenu->x,pMenu->y);
        cprintf("%s",pMenu->content);
        pMenu++;
    }
}
void FrameDraw()
{
    int i,j;
    textbackground(BLACK);
    clrscr();
    window(1,1,80,25);
    textbackground(WHITE);
    clrscr();
    window(1,25,80,25);
    clrscr();
    textbackground(CYAN);
    textcolor(BLACK);
    window(1,2,80,2);
    clrscr();
    window(1,24,80,24);
    clrscr();
    window(1,2,1,24);
    clrscr();
    window(80,2,80,24);
    clrscr();

    window(1,1,80,25);
    for(i=2;i<80;i++)
    {
        gotoxy(i,2);
        cprintf("%c",205);
        gotoxy(i,24);
        cprintf("%c",205);
    }
    for(j=3;j<24;j++)
    {
        gotoxy(1,j);
        cprintf("%c",186);
        gotoxy(80,j);
        cprintf("%c",186);
    }
    gotoxy(1,2);cprintf("%c",201);
    gotoxy(80,2);cprintf("%c",187);
    gotoxy(1,24);cprintf("%c",200);
    gotoxy(80,24);cprintf("%c",188);
    textbackground(WHITE);
    window(2,3,4,23);
    clrscr();
    textbackground(BLACK);
    window(5,3,54,23);
    clrscr();
    textbackground(YELLOW);
    window(56,3,79,12);
    clrscr();
    textbackground(BLUE);
    window(56,14,79,23);
    clrscr();
    window(1,1,80,25);
    textcolor(BLACK);
    textbackground(CYAN);
    for(j=3;j<24;j++)
    {
        gotoxy(55,j);
        cprintf("%c",186);
    }
    for(i=56;i<80;i++)
    {
        gotoxy(i,13);
        cprintf("%c",205);
    }
    gotoxy(55,2);cprintf("%c",203);
    gotoxy(55,24);cprintf("%c",202);
    gotoxy(55,13);cprintf("%c",204);
    gotoxy(80,13);cprintf("%c",185);
    
    gotoxy(21,2);cprintf("Student List");
    gotoxy(60,2);cprintf("Filter Information");
    gotoxy(60,13);cprintf("Input Information");

    gotoxy(4,3);cprintf("No.");
    gotoxy(14,3);cprintf("Name");
    gotoxy(30,3);cprintf("Age");
    gotoxy(35,3);cprintf("Address");

    MenuDraw(MainMenu,5);
}

#define UP_KEY 0x4800
#define DOWN_KEY 0x5000
#define LEFT_KEY 0x4b00
#define RIGHT_KEY 0x4d00
#define F10_KEY 0x4400
#define RETURN_KEY 0x1c0d
#define BS_KEY 0x0e08
#define ESC_KEY 0x011b
int MenuSelect()
{
    int b_Exit=0;
    int result=0;
    int b_SubMenu=0;
    int left=1,top=1,right=1,bottom=1,n;
    char buffer[500];
    MainMenu[0].active=1;
    MenuDraw(MainMenu,5);
    while(!b_Exit)
    {
        switch(bioskey(0))
        {
            case F10_KEY:
            if(b_SubMenu)
            {
                b_SubMenu=0;
                puttext(left,top,right,bottom,buffer);
            }break;
            case ESC_KEY:
            n=SearchActiveMenu(MainMenu,5);
            MainMenu[n].active=0;
            if(b_SubMenu)
            {
                puttext(left,top,right,bottom,buffer);
            }
            MenuDraw(MainMenu,5);result=0;b_Exit=1;break;
            case UP_KEY:
            if(b_SubMenu)
            {
                int m;
                n=SearchActiveMenu(MainMenu,5);
                m=SearchActiveMenu(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
                (MainMenu[n].pSubMenu+m)->active=0;
                if(m==0)
                {
                    (MainMenu[n].pSubMenu+MainMenu[n].n_SubMenu-1)->active=1;
                }
                else
                {
                    (MainMenu[n].pSubMenu+m-1)->active=1;
                }
                MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
            }break;
            case DOWN_KEY:
            if(b_SubMenu)
            {
                int m;n=SearchActiveMenu(MainMenu,5);
                m=SearchActiveMenu(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
                (MainMenu[n].pSubMenu+m)->active=0;
                if(m==(MainMenu[n].n_SubMenu-1))
                {
                    MainMenu[n].pSubMenu->active=1;
                }
                else
                {
                    (MainMenu[n].pSubMenu+m+1)->active=1;
                }
                MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
            }break;    
            case LEFT_KEY:
            n=SearchActiveMenu(MainMenu,5);
            MainMenu[n].active=0;
            n=(n==0)?4:(n-1);
            MainMenu[n].active=1;
            MenuDraw(MainMenu,5);
            if(b_SubMenu)
            {
                puttext(left,top,right,bottom,buffer);
                left=MainMenu[n].pSubMenu->x;
                top=2;
                right=left+20;
                bottom=top+MainMenu[n].n_SubMenu-1;
                gettext(left,top,right,bottom,buffer);
                window(left,top,right,bottom);
                textbackground(WHITE);
                clrscr();
                MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
            }break;
            case RIGHT_KEY:
            n=SearchActiveMenu(MainMenu,5);
            MainMenu[n].active=0;
            n=(n+1)%5;
            MainMenu[n].active=1;
            MenuDraw(MainMenu,5);
            if(b_SubMenu)
            {
                puttext(left,top,right,bottom,buffer);
                left=MainMenu[n].pSubMenu->x;
                top=2;right=left+20;
                bottom=top+MainMenu[n].n_SubMenu-1;
                gettext(left,top,right,bottom,buffer);
                window(left,top,right,bottom);
                textbackground(WHITE);
                clrscr();
                MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
            }break;
            case RETURN_KEY:
            n=SearchActiveMenu(MainMenu,5);
            if(!b_SubMenu)
            {
                b_SubMenu=1;
                left=MainMenu[n].pSubMenu->x;
                top=2;right=left+20;
                bottom=top+MainMenu[n].n_SubMenu-1;
                gettext(left,top,right,bottom,buffer);
                window(left,top,right,bottom);
                textbackground(WHITE);
                clrscr();
                MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
            }
            else
            {
                int m;
                m=SearchActiveMenu(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
                result=(MainMenu[n].pSubMenu+m)->ID;
                MainMenu[n].active=0;
                puttext(left,top,right,bottom,buffer);
                MenuDraw(MainMenu,5);
                b_Exit=1;
            }
        }break;
    }return(result);

}
int SearchActiveMenu(MENU *pMenu,int n)
{
    for(n--;n>=0;n--)
    {
        if(pMenu[n].active) break;
    }return(n);
}




main()
{    
    int b_Exit=0;
    /*textmod(C80);*/
    textbackground(BLACK);
    textcolor(WHITE);
    clrscr();
    FrameDraw();

    while(!b_Exit)
    {
        switch(bioskey(0))
        {
            case F10_KEY:
            if(MenuSelect()==FILE_EXIT)
            b_Exit=1;
            case UP_KEY:
            case DOWN_KEY:break;
        }
    }
}
多多指教

希望 广大 网友多支持!
2008-07-06 20:00
VFive
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-7-7
收藏
得分:0 
菜鸟收到,希望各位大牛多多关照
2008-07-07 02:46
fyjzmx2000
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-7-7
收藏
得分:0 
来学习一下
2008-07-07 09:43
totti133
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-7-7
收藏
得分:0 
555555555555555
#include <iostream>
#include <algorithm>
#include <iterator>
#include <ctime>
using namespace std;
/** arrange the two colors so that color a sits on the left,
color c sits on the right.
Time complexity is O(n), space complexity is O(1). Thus it is
the best algorithm one could have.
*/
void arrangeAC(char*a, int n);
void swap(char& i, char& j);
// randome generator for an array consisting of colors a and c.
void randomGenerator(char* arr, int size);

int main(int argc, char** argv)
{
// prepare the array
int kSize;
cout<<"Please input a number n (n>0): ";
cin>>kSize;
char *a = new char[kSize];
randomGenerator (a, kSize);
cout<<"The oringinal matrix is:\n";
copy(a, a+kSize, std::ostream_iterator<char>(cout, " "));
cout<<endl;
cout<<"----------------------------------------------------------------------\n";
arrangeAC(a, kSize);
cout<<"The arranged matrix is:\n";
copy(a, a+kSize, std::ostream_iterator<char>(cout, " "));
cout<<endl;
delete [] a;
return 0;
}
void arrangeAC(char *a, int n)
{
/**
These 3 variables are the 3 pointers of your case.
*/
int aMarker = 0;
int cMarker = n-1;
int i = 1;
// on the left of a marker, all colors are a
while ( a[aMarker] == 'a' )
{
++aMarker;
}
// on the right of c marker, all colors are c
while ( a[cMarker] == 'c')
{
--cMarker;
}
i = aMarker+1;
while (i <= cMarker)
{
if(a[i] == 'a')
{
if( i > aMarker )
{
swap(a[i], a[aMarker]);
++aMarker;
}
else
++i;
}
else
{
swap(a[i], a[cMarker]);
--cMarker;
}
}
}
void swap(char& i, char& j)
{
char temp = i;
i = j;
j = temp;
}
void randomGenerator(char* arr, int size)
{
srand(time(NULL));
for(int i=0; i<size; ++i)
{
arr[i] = ( (rand() | (rand()<<16) ) % 2 == 0 ? 'a' : 'c');
}
}
谁跟我解释下意思啊
2008-07-07 10:16
蓝色的雪
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-7-7
收藏
得分:0 
谢谢前辈的指点,小弟知道了!出来乍到,受益颇多,请各位多多指教!
2008-07-07 14:38
快速回复:入境随俗:《编程论坛生存手册》
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043524 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved