diff --git a/2209040001/chapter_1/sumOddLengthSubarrays.cpp b/2209040001/chapter_1/sumOddLengthSubarrays.cpp index 3f0722707013a789a7e2ef1e5880bc6c6cf17174..d67562d1f20562d91e33f3008c9f592fadc58986 100644 --- a/2209040001/chapter_1/sumOddLengthSubarrays.cpp +++ b/2209040001/chapter_1/sumOddLengthSubarrays.cpp @@ -1,15 +1,24 @@ -int sumOddLengthSubarrays(int* arr, int arrSize){ +#include + int main() + { int sum = 0; - for(int start = 0; start < arrSize; start++) + int size = 0; + scanf("%d", &size); + int arr[size]; + for(int i = 0; i < size; i++) { - for(int length = 0; length < arrSize; length += 2) - { - int end = start + length; - for(int index = start; index <= end && end < arrSize; index++) - { - sum += arr[index]; - } - } + scanf("%d", &arr[i]); } + for (int start = 0; start < size; start++) + { + for (int length = 0; length < size; length += 2) + { + int end = start + length; + for (int index = start; index <= end && end < size; index++) + { + sum += arr[index]; + } + } + } return sum; -} \ No newline at end of file + } \ No newline at end of file diff --git a/2209040001/chapter_1/twoSum.cpp b/2209040001/chapter_1/twoSum.cpp index 5c03a490c7679b201e1765e42e8ede81a350f7d7..8b21aca8d54b1a6d8e15f89d14eaee58e2522b59 100644 --- a/2209040001/chapter_1/twoSum.cpp +++ b/2209040001/chapter_1/twoSum.cpp @@ -1,14 +1,23 @@ -int* twoSum(int* nums, int numsSize, int target, int* returnSize) { +#include +#include +int main() +{ + int numsSize = 0; + scanf("%d", &numsSize); + int nums[numsSize]; + for(int i = 0; i < numsSize; i++) + { + scanf("%d", &nums[i]); + } + int target = 0; + scanf("%d", &target); for (int i = 0; i < numsSize; ++i) { for (int j = i + 1; j < numsSize; ++j) { if (nums[i] + nums[j] == target) { int* ret = malloc(sizeof(int) * 2); ret[0] = i, ret[1] = j; - *returnSize = 2; - return ret; } } } - *returnSize = 0; - return; + return 0; } \ No newline at end of file diff --git "a/2209040010/chapter1/ lc chapter1 \344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040010/chapter1/ lc chapter1 \344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 1d9484c9cb7ca4f8ee42ffd3fd2012f43a6e4c4b..0000000000000000000000000000000000000000 --- "a/2209040010/chapter1/ lc chapter1 \344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,21 +0,0 @@ -int* twoSum(int* nums, int numsSize, int target, int* returnSize) -{ -int i=0,j=0; -int *a=(int*)malloc(sizeof(int)*2); -for(i=0;i -int main() -{ - int num1 = 0; - int num2 = 0; - int sum = 0; - scanf("%d%d",&num1,&num2); - sum = num1+num2; - printf("sum=%d\n",sum); - return 0; - -} \ No newline at end of file diff --git "a/2209040019/chapter_1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" "b/2209040019/chapter_1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" deleted file mode 100644 index dfadc9c8f1bf422364dc06d86b9f42732b4bbaef..0000000000000000000000000000000000000000 --- "a/2209040019/chapter_1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" +++ /dev/null @@ -1,25 +0,0 @@ -#include -int Sumarr(int* arr, int len) -{ - int res = 0; - for (int i = 0; i < len; i++) //从头开始遍历 - { - for (int j = 1; j <=len- i ; j += 2) - //当前情况下的1,3,5..长度类型的子数组 - { - for (int m = i; m < i + j; m++)//输出当前的子数组的值 - { - res = res + arr[m];//累加值 - } - } - } - return res; -} - -int main() -{ - int arr[]={10,11,12,13,14,15}; - printf("%d\n",Sumarr(arr,sizeof(arr)/sizeof(arr[0]))); - printf("%ld\n",sizeof(arr)); - return 0; -} diff --git a/2209040021/.keep b/2209040021/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/2209040023/chap1/lc-1\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040023/chap1/lc-1\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index e397b4f9731e8d8805b73b6e3c75b09887e3e1b2..0000000000000000000000000000000000000000 --- "a/2209040023/chap1/lc-1\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - int i,j,n; - for(i=0;i& arr) { - int size=arr.size(); - int result=0; - for(int i=0;i -int main(){ -int a,b; -int sum=0; -printf("请输入两个整数\n"); -scanf("%d%d",&a,&b); -printf("sum=%d",a+b); -return 0; -} \ No newline at end of file diff --git a/2209040034/chap1/exp1-1.cpp b/2209040034/chap1/exp1-1.cpp deleted file mode 100644 index f1dcc4304ae24d8ad177030e9847da9cdd6617a7..0000000000000000000000000000000000000000 --- a/2209040034/chap1/exp1-1.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -clock_t start , stop; -double duration1,duration2;//秒 - -void add1(long n) -{ - start=clock(); - long sum=0; - sum=(1+n)*n/2; - stop=clock(); - printf("高斯法:从1到%ld的连续整数和为:%ld\n",n,sum);//输出不是计算过程,所以放在外面 - duration1 = ((double)(stop-start))/CLOCKS_PER_SEC; - printf("高斯法的用时是%f秒\n",duration1); -} - -void add2(long n) -{ - start=0; - stop=0; - start=clock(); - long sum=0; - for(int i=1;i<=n;i++) - { - sum=i+sum; - } - stop=clock(); - printf("累加法:从1到%ld的连续整数和为:%ld\n",n,sum); - duration2 = ((double)(stop-start))/CLOCKS_PER_SEC; - printf("累加法的用时是%f秒\n",duration2); -} - -int main() -{ - long n; - scanf("%ld",&n); - add1(n); - add2(n); - return 0; -} - diff --git a/2209040034/chap1/exp1-3.cpp b/2209040034/chap1/exp1-3.cpp deleted file mode 100644 index 159d7e05fd573a461ac70943507ad7fcabc76a01..0000000000000000000000000000000000000000 --- a/2209040034/chap1/exp1-3.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include - -clock_t start , stop; -double duration1,duration2;//秒 - -void primel1(long n)//找到不是素数的数 -{ - start=clock(); - long i,j,count=1,num;//count为,不是素数的数 - if(n==2) - { - count=1;//1不是素数,2是素数 - } - else - { - for(i=3;i<=n;i++) - { - for(j=2;j -#include -#include - -long add1(long n) -{ - long i,sum=0; - for(i=1;i<=n;i++) - sum+=i; - return sum; -} -void AddTime1(long n) -{ - clock_t t; - long sum; - t=clock(); - sum=add1(n); - t=clock()-t; - printf("方法1:\n"); - printf("结果:1~%d之和:%ld\n",n,sum); - printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); -} -int main() -{ - int n; - printf("n(大于1000000):"); - scanf("%d",&n); - if(n<1000000)return 0; - AddTime1(n); - return 1; -} \ No newline at end of file diff --git "a/2209040037/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\302\267\344\270\252\346\225\260.cpp" "b/2209040037/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\302\267\344\270\252\346\225\260.cpp" deleted file mode 100644 index 4b2823595bfdccc77645e00b31507bfde3fa8404..0000000000000000000000000000000000000000 --- "a/2209040037/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\302\267\344\270\252\346\225\260.cpp" +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -bool prime1(long n) -{ - long i; - for(i=2;i -#include -#include - -long add1(long n) -{ - long i,sum=0; - for(i=1;i<=n;i++) - sum+=i; - return sum; -} -void AddTime1(long n) -{ - clock_t t; - long sum; - t=clock(); - sum=add1(n); - t=clock()-t; - printf("1:\n"); - printf(":1~%d֮:%ld\n",n,sum); - printf("ʱ:%lf\n",((float)t)/CLOCKS_PER_SEC); -} -int main() -{ - int n; - printf("n(1000000):"); - scanf("%d",&n); - if(n<1000000)return 0; - AddTime1(n); - return 1; -} - diff --git "a/2209040040/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" "b/2209040040/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" deleted file mode 100644 index 31d8538b249bb96e283072379e75dd818182b5fb..0000000000000000000000000000000000000000 --- "a/2209040040/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -bool prime1(long n) -{ - long i; - for(i=2;i -#include -#include -//求1+2+.....+n -long add1(long n) -{ - long i,sum=0; - for(i=1;i<=n;i++) - { - sum+=i; - return sum; - } -} -Viod AddTime1(long n) -{ - clock_t t; - long sum; - t=clock(); - sum=add1(n); - t=clock()-t; - printf("方法1:\n"); - printf(" 结果:1~%d之和:%d\n",n,sum); - printf(" 用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); -} -int main() -{ - int n; - print("n(大于1000000):"); - sacnf("%d",&n); - if(n<1000000)return 0; - AddTime1(n); - return 1; -} \ No newline at end of file diff --git "a/2209040042/chapter1/\350\257\276\345\240\202\344\275\234\344\270\232\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" "b/2209040042/chapter1/\350\257\276\345\240\202\344\275\234\344\270\232\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" deleted file mode 100644 index e4da0fee98e7e4f7f7cf3bc39dfa7c944dbcb71b..0000000000000000000000000000000000000000 --- "a/2209040042/chapter1/\350\257\276\345\240\202\344\275\234\344\270\232\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -bool prime1(long n) -{ - long i; - for(i=2;i -#include -#include -bool prime1(long n) -{ - long i; - for(i=2;i -#include -#include - -long add1(long n) -{ - long i,sum=0; - for(i=1;i<=n;i++) - sum+=i; - return sum; -} -void AddTime1(long n) -{ - clock_t t; - long sum; - t=clock(); - sum=add1(n); - t=clock()-t; - printf("方法1:\n"); - printf("结果:1~%d之和:%ld\n",n,sum); - printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); -} -int main() -{ - int n; - printf("n(大于1000000):"); - scanf("%d",&n); - if(n<1000000)return 0; - AddTime1(n); - return 1; -} \ No newline at end of file diff --git "a/2209040045/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040045/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 73e368cf5e6f501da1c9ee7893df46958e109728..0000000000000000000000000000000000000000 --- "a/2209040045/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,15 +0,0 @@ -int* twoSum(int* nums, int numsSize, int target, int* returnSize) { - for (int i = 0; i < numsSize; ++i) { - for (int j = i + 1; j < numsSize; ++j) { - if (nums[i] + nums[j] == target) { - int* ret = malloc(sizeof(int) * 2); - ret[0] = i, ret[1] = j; - *returnSize = 2; - return ret; - } - } - } - *returnSize = 0; - return NULL; -} - diff --git "a/2209040045/chap1/\345\245\207\346\225\260\351\225\277\345\272\246\346\225\260\347\273\204\344\271\213\345\222\214.cpp" "b/2209040045/chap1/\345\245\207\346\225\260\351\225\277\345\272\246\346\225\260\347\273\204\344\271\213\345\222\214.cpp" deleted file mode 100644 index aa635214ddb43370f4f34318d53b9f59828188b4..0000000000000000000000000000000000000000 --- "a/2209040045/chap1/\345\245\207\346\225\260\351\225\277\345\272\246\346\225\260\347\273\204\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,13 +0,0 @@ -int sumOddLengthSubarrays(int* arr, int arrSize){ - int res = 0; - int lEven,lOdd,rEven,rOdd; - for(int i=0;i -#include -#include - -long add1(long n) -{ - long i,sum = 0; -for (i=1;i<=n:i++) -sum+=i; -return sum; -} -void AddTime1(long n) -{ -clock_t t; -long sum; -t=clock(); -sum=add1(n); -t=clock()-t; -printf("方法1:\n"); -printf(" 结果:1~%d之和:%ld\n",n,sum); -printf(" 用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); -} - -long add2(long n) -{ - return n*(n+1)/2; -} -void AddTime2(long n) -{ - clock_t t; - long sum; - t=clock(); - sum=add2(n); - t=clock()-t; - printf("方法2:\n"); - printf(" 结果:1~%d之和:%ld\n",n,sum); - printf(" 用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); -} -int main() -{ - int n; - printf("n(大于1000000):"); - scanf("%d",&n); - if(n<1000000) return 0; - AddTime1(n); - AddTime2(n); - return 1; -} \ No newline at end of file diff --git "a/2209040049/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040049/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 131900d8da99e66728761cf91c49c58a9793bcc5..0000000000000000000000000000000000000000 --- "a/2209040049/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - vector targetnum(2); - map temp_map; - for (int i = 0; i < nums.size(); i++) { - temp_map[nums[i]]= i; - } - for (int i = 0; i < nums.size(); i++) { - int complement = target - nums[i]; - if (temp_map.count(complement) && temp_map[complement] != i) { - targetnum[0]=i; - targetnum[1]=temp_map[complement]; - break;//这个很重要 - } - } - return targetnum; - } -}; diff --git "a/2209040049/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" "b/2209040049/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" deleted file mode 100644 index f0f1d019fb0ca12930c619b3d8481c98452b3c6b..0000000000000000000000000000000000000000 --- "a/2209040049/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - int sumOddLengthSubarrays(vector& arr) { - int result=0; - for(int step=0;step& arr) { - int sum = 0; - int n = arr.size(); - for (int start = 0; start < n; start++) { - for (int length = 1; start + length <= n; length += 2) { - int end = start + length - 1; - for (int i = start; i <= end; i++) { - sum += arr[i]; - } - } - } - return sum; - } -}; \ No newline at end of file diff --git "a/2209040059/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040059/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 32b29d6eb98cc26f4dd46d7f8b1a87bd4544065d..0000000000000000000000000000000000000000 --- "a/2209040059/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -#include -int* twoSum(int* nums, int numsSize, int target, int* returnSize){ - int *a=(int*)malloc(sizeof(int)*2); - int i,j; - for(i=0;i -int* twoSum(int* nums, int numsSize, int target, int* returnSize) -{ - int *a=(int*)malloc(sizeof(int)*2); -for(int i=0;i -int sumOddLengthSubarrays(int* arr, int arrSize) -{ - int sum=0; - for(int i=0;i -int* twoSum(int* nums, int numsSize, int target, int* returnSize) -{ - int*ret=NULL; - for(int i=0;i -int arrSum(int* arr, int start, int end){ - int i, res = 0; - for(i = start; i < start + end; i++) - { - res += arr[i]; - } - - return res; -} -int sumOddLengthSubarrays(int* arr, int arrSize){ - int i = 0; - int j = 0; - int k = 0; - int ans = 0; - - for(i = 1; i <= arrSize; i += 2){ - for(j = 0; j < i; j += i){ - for(k = j; k < arrSize - i + 1;k++){ - ans += arrSum(arr, k ,i); - } - } - } - return ans; -} \ No newline at end of file diff --git "a/2209040077/chapter1/1.1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040077/chapter1/1.1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 2da20624c8aa4e457b46b5dd6b6efc6fef84185a..0000000000000000000000000000000000000000 --- "a/2209040077/chapter1/1.1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - int n = nums.size(); - for (int i = 0; i < n; ++i) { - for (int j = i + 1; j < n; ++j) { - if (nums[i] + nums[j] == target) { - return {i, j}; - } - } - } - return {}; - - } -}; \ No newline at end of file diff --git "a/2209040077/chapter1/1.1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214" "b/2209040077/chapter1/1.1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214" deleted file mode 100644 index ffd8e00e007c5bfc913b87dff938b8749d15a45e..0000000000000000000000000000000000000000 --- "a/2209040077/chapter1/1.1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - int sumOddLengthSubarrays(vector& arr) { - int sum = 0; - int n = arr.size(); - for (int start = 0; start < n; start++) { - for (int length = 1; start + length <= n; length += 2) { - int end = start + length - 1; - for (int i = start; i <= end; i++) { - sum += arr[i]; - } - } - } - return sum; - } -}; \ No newline at end of file diff --git "a/2209040078/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040078/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 747e054f205c6c7a4500fbdd682220ca851ce490..0000000000000000000000000000000000000000 --- "a/2209040078/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - unordered_map hash; - for (int i = 0; i < nums.size(); ++i) - { - if (hash.find(target - nums[i]) != hash.end()) - return { hash[target - nums[i]],i }; - else - hash[nums[i]] = i; - } - return {}; -} -}; \ No newline at end of file diff --git "a/2209040078/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" "b/2209040078/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" deleted file mode 100644 index e3a789ead7920b3fd317769544283b934c41f382..0000000000000000000000000000000000000000 --- "a/2209040078/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - int sumOddLengthSubarrays(vector& arr) { - int sum = 0; - int n = arr.size(); - for (int start = 0; start < n; start++) { - for (int length = 1; start + length <= n; length += 2) { - int end = start + length - 1; - for (int i = start; i <= end; i++) { - sum += arr[i]; - } - } - } - return sum; - } -}; \ No newline at end of file diff --git "a/2209040079/chapter 1/exp1-1\346\261\2021~n\347\232\204\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" "b/2209040079/chapter 1/exp1-1\346\261\2021~n\347\232\204\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" deleted file mode 100644 index 2547c3b1e8d3e2706a3b171b2ec4ef6b9dc39ae9..0000000000000000000000000000000000000000 --- "a/2209040079/chapter 1/exp1-1\346\261\2021~n\347\232\204\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution { -public: - int sumNums(int n) { -int i,sum=0; -for(i=1;i<=n;i++) -{ -sum+=i; -} -return sum; - } -}; \ No newline at end of file diff --git "a/2209040079/chapter 1/exp1-3\346\261\2021~n\344\270\255\347\232\204\346\211\200\346\234\211\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" "b/2209040079/chapter 1/exp1-3\346\261\2021~n\344\270\255\347\232\204\346\211\200\346\234\211\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" deleted file mode 100644 index 2701b18d9e53d7febe4f34eebb46843133cfd53c..0000000000000000000000000000000000000000 --- "a/2209040079/chapter 1/exp1-3\346\261\2021~n\344\270\255\347\232\204\346\211\200\346\234\211\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" +++ /dev/null @@ -1,18 +0,0 @@ -#include -int main() -{ - int n,i,j; - int count=0; - scanf("%d",&n); - printf("素数个数:"); - for(i=2;i<=n;i++) - { - for(j=2;j<=i;j++) - if(i%j==0) - break; - if(i==j) - count++; - } - printf("%d",count); - return 0; -} \ No newline at end of file diff --git "a/2209040081/chapter-2/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" "b/2209040081/chapter-2/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" deleted file mode 100644 index 71613f189faeb792685230a908c4672b853813a3..0000000000000000000000000000000000000000 --- "a/2209040081/chapter-2/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - int sumOddLengthSubarrays(vector& arr) { - int sum = 0; - int n = arr.size(); - for (int start = 0; start < n; start++) { - for (int length = 1; start + length <= n; length += 2) { - int end = start + length - 1; - for (int i = start; i <= end; i++) { - sum += arr[i]; - } - } - } - return sum; - } -}; \ No newline at end of file diff --git "a/2209040081/chapter/\344\270\244\346\225\260\344\271\213\345\222\214" "b/2209040081/chapter/\344\270\244\346\225\260\344\271\213\345\222\214" deleted file mode 100644 index 39274acfc8c9d6a4e306ec5f89ba30a2e483dd1f..0000000000000000000000000000000000000000 --- "a/2209040081/chapter/\344\270\244\346\225\260\344\271\213\345\222\214" +++ /dev/null @@ -1,20 +0,0 @@ -//1.定义整数型数组和整数型数 -//2.用两个for循环遍历数组里面的值,使得两个值之和等于输入的整数型数 -//3.输出对应的数组中元素的下标 - - - -class Solution { -public: - vector twoSum(vector& nums, int target) { - for(int i=0; i=0;i--) - { - if(digits[i] != 9) - { - digits[i]++; - *returnSize = digitsSize; - return digits; - }else{ - digits[i]=0; - } - } - int* ret=malloc((digitsSize+1)*sizeof*ret); - ret[0]=1; - for(int n =1;n INT_MAX || n < INT_MIN ? 0 : n; -} \ No newline at end of file diff --git "a/2224020085/chapter1/leetcode\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2224020085/chapter1/leetcode\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 7cc9787cd7f103795eb8f08383ac28a0be5fa743..0000000000000000000000000000000000000000 --- "a/2224020085/chapter1/leetcode\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include -int main() -{ - int* twoSum(int* nums, int numsSize, int target, int* returnSize); - int i,n,f; - int b[n]; - for(i=0;i -int main() -{ - int* twoSum(int* nums, int numsSize, int target, int* returnSize); - int i,n,m; - int b[n]; - for(i=0;i -#include -int amin() -{ - float log1(int n); - float sqrt1(int n1); - float yuan(int n2); - float log2(int n); - float pingf(int n); - float lif(int n); - float min(int n); - float jiec(int n); - int n,i; - scanf("%d\n",&n); - for(i=1;i<=n;i++) - { - printf("%f%f%f%f%f%f%f%f\n",log1(i),sqrt1(i),yuan(i),log2(i),pingf(i),lif(i),min(i),jiec(i)); - } - return 0; -} -float log1(int n) -{ - float nums1=log10(n)/log10(2); - return nums1; -} -float sqrt1(int n1) -{ - float nums2=sqrt(n1); - return nums2; -} -float yuan(int n2) -{ - return n2; -} -float log2(int n) -{ - float nums3=n*(log10(n)/log10(2)); - return nums3; -} -float pingf(int n) -{ - float nums4=n*n; - return nums4; -} -float lif(int n) -{ - float nums5=n*n*n; - return nums5; -} -float min(int n) -{ - float nums6=pow(2,n); - return nums6; -} -float jiec(int n) -{ - int i,nums7=0,num=1; - for(i=1;i<=n;i++) - { - num=num*i; - } - nums7=nums7+num; - return nums7; -} diff --git "a/2224020085/chapter1/\346\261\2021-n\347\232\204\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" "b/2224020085/chapter1/\346\261\2021-n\347\232\204\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" deleted file mode 100644 index e9a671d704dac5c9c87b06e5616b2898b36c7c19..0000000000000000000000000000000000000000 --- "a/2224020085/chapter1/\346\261\2021-n\347\232\204\350\277\236\347\273\255\346\225\264\346\225\260\345\222\214.cpp" +++ /dev/null @@ -1,24 +0,0 @@ -#include -int main() -{ - int add1(int n); - int add2(int n); - int num1; - scanf("%d\n",&num1); - printf("%d\n",add1(num1)); - printf("%d\n",add2(num1)); -} -int add1(int n) -{ - int i; - int sum=0; - for(i=1;i<=n;i++) - { - sum=sum+i; - } - return sum; -} -int add2(int n) -{ - return n*(n+1)/2; -} \ No newline at end of file diff --git "a/2224020085/chapter1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" "b/2224020085/chapter1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" deleted file mode 100644 index 41db4a5db496f2799ec2f23eaa84de79afc10b4b..0000000000000000000000000000000000000000 --- "a/2224020085/chapter1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260.cpp" +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -int main() -{ - int way1(int n); - int way2(int n); - int num; - scanf("%d\n",&num); - printf("%d\n%d\n",way1(num),way2(num)); -} -int way2(int n) -{ - int n1,k,i,m=0; - for(n1=1;n1<=n;n=n+2) - { - k=sqrt(n1); - for(i=2;i<=k;i++) - if(n%i==0) break; - if(i>=k+1) - m=m+1; - } - return m; -} -int way1(int n) -{ - int count=0; - int i=0; - for(i=2;i -int main() -{ - int link(int n); - int num; - scanf("%d\n",&num); - printf("%d\n",link(num)); -} -int link(int n) -{ - int i,j,sum=0; - int num=1; - scanf("%d\n",&n); - for(i=1;i<=n;n++) - { - for(j=1;j<=i;j++) - { - num=num*j; - } - sum=sum+num; - } - return sum; -} \ No newline at end of file diff --git "a/2224020087/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" "b/2224020087/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" deleted file mode 100644 index 71613f189faeb792685230a908c4672b853813a3..0000000000000000000000000000000000000000 --- "a/2224020087/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - int sumOddLengthSubarrays(vector& arr) { - int sum = 0; - int n = arr.size(); - for (int start = 0; start < n; start++) { - for (int length = 1; start + length <= n; length += 2) { - int end = start + length - 1; - for (int i = start; i <= end; i++) { - sum += arr[i]; - } - } - } - return sum; - } -}; \ No newline at end of file diff --git "a/2224020099/chapter_1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2224020099/chapter_1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 155c76836367d79ec6b4e3449173f6c6d35af4c2..0000000000000000000000000000000000000000 --- "a/2224020099/chapter_1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -int* twoSum(int* nums, int numsSize, int target, int* returnSize){ - int *a = (int *)malloc(sizeof(int) * 2); - int i, j; - for (i = 0; i < numsSize - 1; i++) { - for (j = i + 1; j < numsSize; j++) { - if (nums[i] + nums[j] == target) { - a[0] = i; - a[1] = j; - printf("%d---%d",i,j); - *returnSize = 2; - return a; - } - } - } - *returnSize = 0; - return a; - } \ No newline at end of file diff --git "a/2224020099/chapter_1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\351\233\206\345\220\210.cpp" "b/2224020099/chapter_1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\351\233\206\345\220\210.cpp" deleted file mode 100644 index bb7b0f70e948e0b533ff8952aae2923c1194af41..0000000000000000000000000000000000000000 --- "a/2224020099/chapter_1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\351\233\206\345\220\210.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution { -public: - int sumOddLengthSubarrays(vector& arr) { - int sum = 0; - int n = arr.size(); - for (int start = 0; start < n; start++) { - for (int length = 1; start + length <= n; length += 2) { - int end = start + length - 1; - for (int i = start; i <= end; i++) { - sum += arr[i]; - } - } - } - return sum; - } - - }; \ No newline at end of file diff --git a/2224020102/chap1/ch1.1.1.cpp b/2224020102/chap1/ch1.1.1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..59b4537a00ec3c1084d963dcf171e397212e48fe --- /dev/null +++ b/2224020102/chap1/ch1.1.1.cpp @@ -0,0 +1,22 @@ +#include +int main() +{ + int s=0,n,i; + scanf("%d",&n); + for(i=1;i<=n;i++) + { + s+=i; + } + printf("sum = %d",s); +} +void AddTime1(long n) +{ +clock_t t; +long sum; +t = clock(); +sum = add1(n); +t = clock() - t; +printf("方法1:\n"); +printf(" 结果:1~%d之和:%ld\n",n,sum); +printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); +} diff --git a/2224020102/chap1/ch1.2.1.cpp b/2224020102/chap1/ch1.2.1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..204b5cb11d47f5afca89f9902e7c8236433808e1 --- /dev/null +++ b/2224020102/chap1/ch1.2.1.cpp @@ -0,0 +1,41 @@ +#include +#include + +int main() +{ + long long int t,j,u=0; + int isprime(int n); + printf("请输入一个数:"); + scanf("%d",&t); + for(j=1;j<=t;j++) + { + if (isprime(j)==1) u++; + } + printf("从1到%d总共有%d个素数",t,u); + return 0; +} + +int isprime(int n) +{ + int i; + if(n==2) return 1; + else if(n==1||n%2==0) return 0; + for (i=3;i<=sqrt(n)+1;i+=2) + { + if(n%i==0) return 0; + } + return 1; +} +void PrimeTime(long n) +{ +clock_t t; +long sum=0, i; +t = clock(); +for (i = 2; i <= n;i++) + if (prime(i)) + sum++; +t = clock()-t; +printf("方法1:\n"); +printf(" 结果:2~%d素数个数:%ld\n",n,sum); +printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); +} diff --git a/2224020102/chap1/chi.1.1.2.cpp b/2224020102/chap1/chi.1.1.2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed5511b1d9ffad26cddc9afcae8f49d6d537ec5f --- /dev/null +++ b/2224020102/chap1/chi.1.1.2.cpp @@ -0,0 +1,20 @@ +#include +int main() +{ + int i,sum=0,n; + scanf("%d",&n); + sum=(1+n)*n/2; + printf("%d\n",sum); + return 0; + } +void AddTime1(long n) +{ +clock_t t; +long sum; +t = clock(); +sum = add1(n); +t = clock() - t; +printf("方法:\n"); +printf(" 结果:1~%d之和:%ld\n",n,sum); +printf("用时:%lf秒\n",((float)t)/CLOCKS_PER_SEC); +} diff --git "a/2224020087/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2224020102/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" similarity index 39% rename from "2224020087/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" rename to "2224020102/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" index a46398c00c696f5160c2aa417447e99aa34ebe72..6ad49e4fa438ae8d5a971ec5d6031775fc5b548b 100644 --- "a/2224020087/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ "b/2224020102/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" @@ -1,14 +1,18 @@ class Solution { public: - vector twoSum(vector& nums, int target) { + vector twoSum(vector& nums, int target) + { int n = nums.size(); - for (int i = 0; i < n; ++i) { - for (int j = i + 1; j < n; ++j) { - if (nums[i] + nums[j] == target) { + for (int i = 0; i < n - 1; ++i) + { + for (int j = i + 1; j < n; ++j) + { + if (nums[i] == target - nums[j]) + { return {i, j}; } } } return {}; } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/2224020106/chapter1/exp1-1.cpp b/2224020106/chapter1/exp1-1.cpp deleted file mode 100644 index 2d7f4d547e9ade20bffa0c6a6b1b4e7e08890f15..0000000000000000000000000000000000000000 --- a/2224020106/chapter1/exp1-1.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -long add1(long n){ - long i,sum = 0; - for(i = 0;i<=n;i++) - sum += i; - return sum; -} -long add2(long n){ - return n * (n + 1)/2; -} -int main() -{ - int n; - printf("输入一个n"); - scanf("%d",&n); - printf("使用累加法:%ld\n",add1(n)); - printf("使用高斯法:%ld\n",add2(n)); - return 1; -} \ No newline at end of file diff --git a/2224020106/chapter1/exp1-3.cpp b/2224020106/chapter1/exp1-3.cpp deleted file mode 100644 index 077d2fc1276b9b58bcec37393159de3649cf4bbe..0000000000000000000000000000000000000000 --- a/2224020106/chapter1/exp1-3.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(){ - long n; - scanf("输入一个%d,判断是否为素数",&n); -} \ No newline at end of file diff --git a/2224020106/chapter1/lc-1.cpp b/2224020106/chapter1/lc-1.cpp deleted file mode 100644 index 97ab3d711b32e0d4797a55deef256a7a6f9bfa82..0000000000000000000000000000000000000000 --- a/2224020106/chapter1/lc-1.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - int n = nums.size(); - for(int i = 0;i < n;i++){ - for(int j = i + 1;j < n;j++){ - if (nums[i]+nums[j] == target){ - return {i,j}; - } - } - } - return {}; - } -}; \ No newline at end of file diff --git a/2224020106/chapter1/lc-1588.cpp b/2224020106/chapter1/lc-1588.cpp deleted file mode 100644 index 7659ff3a76b687e6a53504a2f18061e00546a135..0000000000000000000000000000000000000000 --- a/2224020106/chapter1/lc-1588.cpp +++ /dev/null @@ -1,17 +0,0 @@ -class Solution { -public: - int sumOddLengthSubarrays(vector& arr) { - int sum = 0; - int n = arr.size(); - for (int i = 0; i < n; i++) { - int temp = 0; - for(int j = i; j < n; j++) { - temp += arr[j]; - if((j - i)% 2 == 0) { - sum += temp; - } - } - } - return sum; - } -}; \ No newline at end of file diff --git "a/2225010064/chapter1/lc_1\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2225010064/chapter1/lc_1\344\270\244\346\225\260\344\271\213\345\222\214.cpp" deleted file mode 100644 index 2781a7955cd4be482a7592c919fd5a4f8d37f89e..0000000000000000000000000000000000000000 --- "a/2225010064/chapter1/lc_1\344\270\244\346\225\260\344\271\213\345\222\214.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - int i,j; - for(i=0;i int main(void) { - printf("Hello "); + printf("Hello World\n"); return 0; }