#include<stdio.h> #include<stdlib.h> #pragma warning (disable:4996) typedef struct { int data[1000]; int length; }SqList; void CreatList(SqList *&L, int a[], int n) { int i = 0, k = 0; L = (SqList*)malloc(sizeof(SqList)); while (i < n) { L->data[k]=a[i]; k++; i++; } L->length = k; } void InitList(SqList *&L) { L = (SqList*)malloc(sizeof(SqList)); L->length = 0; } void Destroy(SqList *&L) { free(L); } void fun(SqList *L, int x, int y) { int k = 0; for (int i = 0; i < L->length; i++) { if (L->data[i] < x||L->data[i] > y) { L->data[k] = L->data[i]; k++; } } L->length =k; } void fun2(SqList *L, int x, int y) { int i, j; for (i = 0; i < L->length; i++) { if (L->data[i] >= x && L->data[i] <= y) { for (j = i; j < L->length - 1; j++) L->data[j] = L->data[j + 1]; L->length--; } } } void print(SqList *L) { for (int i = 0; i < L->length; i++) { printf("%d ", L->data[i]); } printf("\n"); } int main() { int n,a[1000],x,y; scanf("%d %d %d", &n,&x,&y); for (int i = 0; i < n; i++) scanf("%d", &a[i]); SqList* L; InitList(L); CreatList(L,a,n); fun(L, x, y); print(L); return 0; }顺序表
#include<stdio.h> #include<time.h> #pragma warning (disable:4996) long long int factor1(int n) { long long int ans = 0, total = 1; for (int i = 1; i <= n; i++) { total = 1; for (int j = 1; j <= i; j++) { total *= j; } ans += total; } return ans; } long long int factor2(int n) { long long int ans = 0, total = 1; for (int i = 1; i <= n; i++) { total *= i; ans += total; } return ans; } int main() { int n,begin,end; scanf("%d", &n); begin = clock(); printf("1: %lld\n", factor1(n)); end = clock(); printf("time: %dms\n", end - begin); begin = clock(); printf("2: %lld\n", factor2(n)); end = clock(); printf("time: %dms\n", end - begin); return 0; }
标签:int,暂存,代码,++,length,SqList,data,void From: https://www.cnblogs.com/Phantomhive/p/17680867.html