spyware Đại Bàng Tinh
Tổng số bài gửi : 116 Join date : 04/06/2009 Age : 39 Đến từ : HN
| Tiêu đề: [code 11] ::ai làm chưa, post lên cho tham khảo chut Tue Jun 30, 2009 3:12 pm | |
| - ai có code hoàn chỉnh của code 11 post len giùm nhé. thanks | |
|
Join date : 01/01/1970
| Tiêu đề: Re: [code 11] ::ai làm chưa, post lên cho tham khảo chut Tue Jun 30, 2009 11:11 pm | |
| chưa làm mấy hôm toàn chơi hehehe | |
|
spyware Đại Bàng Tinh
Tổng số bài gửi : 116 Join date : 04/06/2009 Age : 39 Đến từ : HN
| Tiêu đề: Re: [code 11] ::ai làm chưa, post lên cho tham khảo chut Wed Jul 01, 2009 5:25 pm | |
| - hix mãi mới làm được code 11_2 này. test cũng khá mỏi tay rồi, anh em test kỹ lại giùm #include #include #include // declare all function void input(char s[]); int checkword(char s[]); int checkspace(char s[]); int checklower(char s[]);
//define all function void main() { int i,n,t; char str[100]; clrscr(); input(str); t=checkword(str); if(t>=2 && t<=4) printf("\nThere is %d words in string : Correct",t); else printf("\nThere is %d words in string: Incorrect",t); if(checkspace(str)) printf("\nCheck space: Correct"); else printf("\nCheck space: Incorrect"); if(checklower(str)) printf("\nCheck lower: Correct\n\n\n"); else printf("\nCheck lower: Incorrect\n\n\n"); if((t>=2&&t<=4)&&checkspace(str)&&checklower(str)) { // puts(str); printf("%s",str); printf(" --> Correct\n"); } else { // puts(str); printf("%s",str); printf(" --> Incorrect\n"); } getch(); } void input(char s[]) { printf("Input string:"); fflush(stdin); gets(s); } int checkword(char s[]) { int i,j,len=strlen(s); int count=0; for(i=0;i if(s[i]!=' ' && s[i] != '\t') { for(j=i+1;j<=len;j++) if(s[j]==' ' || s[j]=='\t'||s[j]=='\0') { count++; i=j; break; } } return count; } int checkspace(char s[]) { int i,n=0; for(i=0;i if(s[i]==' ') n++; if(checkword(s)==n+1) return 1; return 0; } int checklower(char s[]) { int i,j; for(i=0;i if(s[i]!=' ' && s[i]!='\t') if (s[i] < 'A' || s[i] > 'Z') return 0; else { for(j=i+1;s[j]!=' '&& s[j]!='\t'&& s[j]!='\0';j++) if(s[j]<'a' || s[j]>'z') return 0; i=j; } return 1; } | |
|
haph86 Gà mới lớn
Tổng số bài gửi : 40 Join date : 04/06/2009
| Tiêu đề: Re: [code 11] ::ai làm chưa, post lên cho tham khảo chut Wed Jul 01, 2009 8:43 pm | |
| post code lỗi mất rồi, Hiến post lại cho anh em xem với nhé | |
|
spyware Đại Bàng Tinh
Tổng số bài gửi : 116 Join date : 04/06/2009 Age : 39 Đến từ : HN
| Tiêu đề: Re: [code 11] ::ai làm chưa, post lên cho tham khảo chut Wed Jul 01, 2009 9:33 pm | |
| - spyware đã viết:
- - hix mãi mới làm được code 11_2 này. test cũng khá mỏi tay rồi, anh em test kỹ lại giùm
- Code:
-
#include<conio.h> #include<stdio.h> #include<string.h> // declare all function void input(char s[]); int checkword(char s[]); // đếm số từ int checkspace(char s[]); /* kiểm tra: đầu và đuôi không có dấu cách, giữa các từ có ! 1 dấu cách */ int checklower(char s[]); /* mỗi từ bắt đầu bằng ký tự hoa và sau đó là ký tự thường */
//define all function void main() { int i,n,t; char str[100]; clrscr(); input(str); t=checkword(str); if(t>=2 && t<=4) printf("\nThere is %d words in string : Correct",t); /* cái này chủ yếu để kiểm tra xem hàm đếm số từ có chính xác hay không */ else printf("\nThere is %d words in string: Incorrect",t); if(checkspace(str)) printf("\nCheck space: Correct"); /* cái này kiểm tra hàm: kiểm tra dấu cách giữa các từ và không có dấu cách ở đầu và cuối câu::: lúc đó thì số từ = số dấu cách + 1 */ else printf("\nCheck space: Incorrect"); if(checklower(str)) printf("\nCheck lower: Correct\n\n\n"); /* cái này kiểm tra xem trong mỗi từ, có phải bắt đầu bằng ký tự hoa, các ký tự sau đó phải là ký tự thường hay không */ else printf("\nCheck lower: Incorrect\n\n\n"); if((t>=2&&t<=4)&&checkspace(str)&&checklower(str)) /* cái này đúng khi 3 ý trên cùng đúng */ { // puts(str); printf("%s",str); printf(" --> Correct\n"); } else { // puts(str); printf("%s",str); printf(" --> Incorrect\n"); } getch(); } void input(char s[]) { printf("Input string:"); fflush(stdin); gets(s); } int checkword(char s[]) { int i,j,len=strlen(s); int count=0; for(i=0;i<len;i++) if(s[i]!=' ' && s[i] != '\t') /*bỏ qua các ký tự trắng trước mỗi từ (gặp ký tự hợp lệ đầu tiên)*/ { for(j=i+1;j<=len;j++) // trong mỗi từ if(s[j]==' ' || s[j]=='\t'||s[j]=='\0') /*khi gặp khoảng trắng hoặc null thì ngừng kt*/ { count++; i=j; break; } } return count; } int checkspace(char s[]) /* với yêu cầu đề ra thì số từ = số dấu cách +1*/ { int i,n=0; for(i=0;i<strlen(s);i++) if(s[i]==' ') n++; if(checkword(s)==n+1) return 1; return 0; } int checklower(char s[]) { int i,j; for(i=0;i<strlen(s);i++) /*bỏ qua các khoảng trắng trước mỗi từ */ if(s[i]!=' ' && s[i]!='\t') if (s[i] < 'A' || s[i] > 'Z') /*kiểm tra ký tự hoa đầu mỗi từ*/ return 0; else { for(j=i+1;s[j]!=' '&& s[j]!='\t'&& s[j]!='\0';j++) if(s[j]<'a' || s[j]>'z') /*kiểm tra ký tự thường trong mỗi từ*/ return 0; i=j; } return 1; } | |
|
Join date : 01/01/1970
| Tiêu đề: Re: [code 11] ::ai làm chưa, post lên cho tham khảo chut Tue Jul 07, 2009 12:17 am | |
| nhanh tay đấy hehehe spamer đây | |
|
Sponsored content
| Tiêu đề: Re: [code 11] ::ai làm chưa, post lên cho tham khảo chut | |
| |
|