輸入一頁文字,程序可以統(tǒng)計出文字、數(shù)字、空格的個數(shù)。靜態(tài)存儲一頁文章,每行最多不超過80個字符,共N行;
成都創(chuàng)新互聯(lián)公司是專業(yè)的大關(guān)網(wǎng)站建設(shè)公司,大關(guān)接單;提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行大關(guān)網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!5.2問題分析和任務(wù)定義(1)分別統(tǒng)計出其中英文字母數(shù)和空格數(shù)及整篇文章總字?jǐn)?shù);
(2)統(tǒng)計某一字符串在文章中出現(xiàn)的次數(shù),并輸出該次數(shù);
(3)刪除某一子串,并將后面的字符前移。
存儲結(jié)構(gòu)使用線性表,分別用幾個子函數(shù)實現(xiàn)相應(yīng)的功能;
輸入數(shù)據(jù)的形式和范圍:可以輸入大寫、小寫的英文字母、任何數(shù)字及標(biāo)點符號。
輸出形式:
(1)分行輸出用戶輸入的各行字符;
(2)分4行輸出"全部字母數(shù)"、"數(shù)字個數(shù)"、"空格個數(shù)"、"文章總字?jǐn)?shù)"
(3)輸出刪除某一字符串后的文章;
5.3 數(shù)據(jù)類型和系統(tǒng)設(shè)計(1)存儲結(jié)構(gòu)設(shè)計
使用鏈表存儲結(jié)構(gòu)
(2)系統(tǒng)功能設(shè)計
#include
#include
typedef struct line?????????? //定義串結(jié)構(gòu)??
{
char *data;???????????? //定義指向字符的指針
struct line *next;????????? //定義指向下一個結(jié)點的指針
}LINE;???????
(1)創(chuàng)建鏈表,向里面輸入文本數(shù)據(jù)
void OutPut(LINE * &head)? //向屏幕輸出文字
{
LINE *p=head;??????????? //定義指針p
do{
?????? printf("%s\n",p->data);??
}??
while((p=p->next)!=NULL);????? //遍歷鏈表
printf("\n");
}
(2)主函數(shù)
void menu(){
printf("***********編輯指令***********\n");
printf("1:統(tǒng)計文章中總字符數(shù)????????? \n");
printf("2:統(tǒng)計文章中空格個數(shù)????????? \n");
printf("3:統(tǒng)計文章中數(shù)字個數(shù)????????? \n");
printf("4:統(tǒng)計文章中英文字母數(shù)??????? \n");
printf("5:刪除文章中指定字符串??????? \n");
printf("6:統(tǒng)計文章中指定字符串出現(xiàn)次數(shù)\n");
printf("******************************\n");
}
void Create(LINE * &head)
{??????
printf ("請輸入文章,每行最多80個字符,以Ctrl+E(^E)為結(jié)束符\n");
LINE *p=new LINE;????????????? //首先為鏈表建立一個附加表頭結(jié)點????????????????????????????????????
head=p;??????????????????????? //將付給表頭指針
char tmp[100];
while(1)??
{
?????? gets(tmp);????????????????? //輸入字符串
?????? if(strlen(tmp)>80)
?????? {
?????????????? printf("每行最多輸入80個字符!");
?????????????? break;
?????? }
?????? if(tmp[0]==5)break;????????? //如果發(fā)現(xiàn)輸入^E,則退出輸入??
?????? p=p->next=new LINE;
?????? p->data=new char[strlen(tmp)+1];??????? //為結(jié)點分配空間??
?????? strcpy(p->data,tmp);
?????? if(tmp[strlen(tmp)-1]==5)??? //除去最后一個控制符^E???? ?
?????? {??????
?????????????? p->data[strlen(tmp)-1]='\0';
?????????????? break;
?????? }
}
p->next=NULL;????????????????? //最后一個指針為空
head=head->next;
printf("\n");
menu();
}
(3)統(tǒng)計英文字母數(shù)
void CountLetter(LINE * &head)??? //統(tǒng)計英文字母數(shù)
{
LINE *p=head;
int count=0;
do{?????? ????
?????? int Len=strlen(p->data);? //計算當(dāng)前data里的數(shù)據(jù)元素個數(shù)
?????? for(int i=0;i ?????????????? if((p->data[i]>='a'&&p->data[i]<='z')||(p->data[i]>='A'&&p->data[i]<='Z'))?????????????????????????? ??????????????????????? count++;???????????????????? }????????????????????????????? //計算字母數(shù) while((p=p->next)!=NULL);????? //遍歷鏈表 printf("文章中英文字母個數(shù): %d \n", count);//返回文章里 printf("******************************\n"); printf("\n"); menu(); } (4)統(tǒng)計數(shù)字?jǐn)?shù) void CountNumber(LINE * &head) {?????? LINE *p=head; int count=0;???? do{?????? ???? ?????? int Len=strlen(p->data); ?????? for(int i=0;i ?????????????? if(p->data[i]>=48 && p->data[i]<=57)count++;????? } while((p=p->next)!=NULL);???????????????? printf("文章中數(shù)字個數(shù): %d \n",count); printf("******************************\n"); printf("\n"); menu(); } (5)統(tǒng)計空格數(shù) void CountSpace(LINE * &head) { LINE *p=head;?????????????????????????????????????????? int count=0; do{?????? ???? ?????? int Len=strlen(p->data); ?????? for(int i=0;i ?????????????? if(p->data[i]==32)count++;???? }?? while((p=p->next)!=NULL);???? printf("文章中空格個數(shù): %d \n", count); printf("******************************\n"); printf("\n"); menu(); } (6)顯示所有字母的個數(shù) void CountAll(LINE * &head) {?????? LINE *p=head;???????????????????????????? int count=0;???????????? do{?? ?????? count+=strlen(p->data); }?? while((p=p->next)!=NULL);???????????????? printf("文章總字?jǐn)?shù): %d \n",count); printf("******************************\n"); printf("\n"); menu(); } (7)尋找字符串 void FindString(LINE * &head) { LINE *p=head; int count=0; int len1=0;???????????????????????????? int len2; int i,j,k; char str1[20];? printf("\n"); printf("請輸入要統(tǒng)計的字符串:"); scanf("%s",str1);????? len2=strlen(str1);??? do {? ?????? len1=strlen(p->data);?????????????????? ???????? ?????? for(i=0;i ?????? {?? ????????? ?????????????? if(p->data[i]==str1[0])????????????????????? ?????????????? {???????????????????????? ??????????????????????? k=0;?????????????????? ??????????????????????? for(j=0;j ???????????????????????????????? if(p->data[i+j]==str1[j]) k++;???????????????????????????? ???????????????????????????????? if(k==len2)??? {count++;i=i+k-1;}??????????????????????????????????? ?????????????? }???????????????????????? ?????? }??????????????? }?? while((p=p->next)!=NULL);//遍歷鏈表 printf("該字符串在文中出現(xiàn)的次數(shù): %d \n",count);?? printf("******************************\n"); printf("\n");???? menu();??? } (8)刪除目標(biāo)字符串 void delstringword(char *s,char *str)????????? //刪除指定的字符串 {??????????????????????? //*s為輸入的字符串,*str為將要刪除的字符??????? char *p=strstr(s,str);??? //從字符串中尋找str第一次出現(xiàn)的位置 char tmp[80]; int len=strlen(s); int i=len-strlen(p);?? int j=i+strlen(str);??? int count=0;???? for(int m=0;m for(int n=j;n tmp[count]='\0'; strcpy(s,tmp);???????????????????????? ??????? } void DelString(LINE * &head) {?????? LINE *p=head; char str[20];??? printf("請輸入要刪除的字符串: ");?????? scanf("%s",str);??????? do {??????????????? ?????? if(strstr(p->data,str)!=NULL)delstringword(p->data,str);??????????????? }?????? while((p=p->next)!=NULL);???? printf("刪除指定字符串后的文章為: \n");?? OutPut(head); printf("******************************\n"); printf("\n");???? menu();??? } int main() {?????? LINE *head;???? int i; Create(head);? for(;;)??????????????? {??????????????? ?????? printf("執(zhí)行指令: ");??????????????? ?????? scanf("%d",&i);???????????????? ?????? switch(i)??????????????????? ?????? {???????????????????????? ?????? case 1:CountAll(head);break;????????????????? ?????? case 2:CountSpace(head);break;???????????????????? ?????? case 3:CountNumber(head);break;???????????????? ?????? case 4:CountLetter(head);break;???????????????????? ?????? case 5:DelString(head);break;???????? ?????? case 6:FindString(head);break;??????????????? ?????? default:printf("指令輸入錯誤\n\n");????????????????????? ?????? }?????? }?????? } 1.輸入文章: 2.進行功能操作 你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
本文題目:文章編輯系統(tǒng)的設(shè)計與實現(xiàn)-創(chuàng)新互聯(lián)
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、響應(yīng)式網(wǎng)站、企業(yè)建站、商城網(wǎng)站、定制開發(fā)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)
URL標(biāo)題:http://aaarwkj.com/article42/cdpiec.html
猜你還喜歡下面的內(nèi)容