回复 10楼 小李探花
原来要把ASCII码考虑进去这题有得搞了~有时间我再做做看~看上去不简单欸~
[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
#include <stdio.h> #include <stdlib.h> struct Data { int year; int month; int day; }; struct library { char booktitle[50]; char author[10]; struct Data data; char publishunit[100]; int lendnum; int stocknum; }; int main() { int i, j, n, temp = 0; struct library book[n]; printf("请输入要处理的图书数量:\n"); fflush(stdout); scanf("%d", &n); for (i = 0; i < n; i++) { printf("请输入第%d本书的信息:\n", i + 1); printf("书名:"); fflush(stdout); scanf("%s", &book[i].booktitle); printf("作者:"); scanf("%s", &book[i].author); printf("出版年月:"); scanf("%s", &book[i].data); printf("出版社:"); scanf("%s", &book[i].publishunit); printf("借出数:"); scanf("%s", &book[i].lendnum); printf("库存数:"); scanf("%s", &book[i].stocknum); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (book[i].publishunit < book[j].publishunit) { temp = book[i]; book[i] = book[j]; book[j] = temp; } } printf("\n排序后的图书信息:"); for (i = 0; i < n; i++) { printf("\n书名: %s\n, 作者: %s\n, 出版年月: %s\n, 出版社: %s\n, 借出数: %s\n, 库存数:%s\n", book[i].booktitle, book[i].author, book[i].data, book[i].publishunit, book[i].lendnum, book [i].stocknum); } } return EXIT_SUCCESS; }
#include<stdio.h> #include<stdlib.h> void fun(char *str,char *p,int L,int M) { int i=0; int j=0; int k=0; char *p2=p; char *p3=NULL; for (;k<M;p=p2+i,k++) { int flag=0; p3=p; for (j=0;j<L;j++,p+=L) { p+=L; if (*(p+L)=='\0') { flag=1; break; } if (*p==*p3) { flag=1; break; } } if (flag) break; } if (k==M) printf("满足条件的子串:%.*s\n",M*L,p2); p=p2; if (*(p+L*M)) fun(str,++p,L,M); } int main() { char S[100000]; int L,M; printf("请输入字符串S:"); gets(S); printf("请输入M和L:"); scanf("%d%d",&L,&M); fun(S,S,L,M); return 0; }
#include <stdio.h> #include <stdlib.h> struct Data { int year; int month; int day; }; struct library { char booktitle[50]; char author[10]; struct Data data; char publishunit[100]; int lendnum; int stocknum; }; int main() { int i, j, n;// struct library temp;//数据类型问题,temp应该为结构体变量~ struct library book[100];//book[n],[]里面不能为变量 printf("请输入要处理的图书数量:\n"); fflush(stdout); scanf("%d", &n); for (i = 0; i < n; i++) { printf("请输入第%d本书的信息:\n", i + 1); printf("书名:"); fflush(stdout); scanf("%s", &book[i].booktitle); printf("作者:"); scanf("%s", &book[i].author); printf("出版年:"); scanf("%d", &book[i].data.year); printf("出版月:"); scanf("%d", &book[i].data.month); printf("出版日:"); scanf("%d", &book[i].data.day); printf("出版社:"); scanf("%s", &book[i].publishunit); printf("借出数:"); scanf("%d", &book[i].lendnum); printf("库存数:"); scanf("%d", &book[i].stocknum); } for (i = 0; i < n; i++) for (j = 0; j <n-i-1; j++) if (book[i].publishunit < book[j].publishunit) { temp = book[j]; book[j] = book[j]; book[j] = temp; } printf("\n排序后的图书信息:"); for (i = 0; i < n; i++) { printf("\n"); printf("书名: %s\n",book[i].booktitle); printf("作者: %s\n",book[i].author); printf("出版年月日:%d-%d-%d\n",book[i].data.year,book[i].data.month,book[i].data.day); printf("出版社: %s\n",book[i].publishunit); printf("借出数: %d\n",book[i].lendnum); printf("库存数: %d\n",book[i].stocknum); } return EXIT_SUCCESS; }