- 博客(29)
- 收藏
- 关注
原创 6kyu Multiplication table
Your task, is to create NxN multiplication table, of size provided in parameter.for example, when given size is 3:1 2 32 4 63 6 9for given example, the return value should be: [[1,2,3],[2,4,6],[3,6,9]]Note: in C, you must return an allocated table of
2021-09-09 02:30:38
165
1
原创 5kyu Product of consecutiveFib numbers
The Fibonacci numbers are the numbers in the following integer sequence (Fn):0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, …such asF(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.Given a number, say prod (for product), we search two Fibonacci nu
2021-09-09 02:05:35
250
原创 equal sides of an array
You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, retur
2021-09-08 21:27:52
93
原创 7 kyu sum of the first nth term of series
Given a rational number nn >= 0, with denominator strictly positiveas a string (example: “2/3” in Ruby, Python, Clojure, JS, CS, Go)or as two strings (example: “2” “3” in Haskell, Java, CSharp, C++, Swift, Dart)or as a rational or decimal number (ex
2021-09-02 16:10:43
142
原创 5 kyu some egyptian fractions
Given a rational number nn >= 0, with denominator strictly positiveas a string (example: “2/3” in Ruby, Python, Clojure, JS, CS, Go)or as two strings (example: “2” “3” in Haskell, Java, CSharp, C++, Swift, Dart)or as a rational or decimal number (ex
2021-09-02 15:08:43
107
原创 6 kyu —Binary to Text (ASCII) Conversion
#include <stdlib.h>#include <math.h>#include <string.h>#include <stdio.h>char *binary_to_string(const char *binary) {char *ascii = (char *)malloc( sizeof(char) * strlen( binary ) );int i, cnt = 0;while( *binary ){ char s
2021-07-03 16:08:19
80
原创 6 — Irreducible Sum of Rationals
#include <stdlib.h>int gcd(int m, int n){ if(m*n == 0) return m == 0?n:m; if(m>n) return gcd(m%n,n); else return gcd(n%m,m); }int* sumFracts(int lst[][2], int row) {int *result = (int *)malloc( 2 * sizeof(int) );
2021-07-03 15:27:21
63
原创 6–kyu. Hidden “Cubic“ numbers
#include <ctype.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>char* isSumOfCubes(char const * str) { int i, sum = 0, cnt = 0, f = 0; char *target = (char *)calloc( strlen(str), sizeof(char
2021-07-03 14:41:20
102
原创 6–kyu.array.diff
#include <stdlib.h>#include <stdbool.h>#include <stdio.h>int *array_diff(const int *arr1, size_t n1, const int *arr2, size_t n2, size_t *z){int *target = (int *)malloc( 100 * sizeof(int) ), i, j, cnt = 0;bool f1[n1], f2[n2];for(
2021-07-03 13:04:06
56
原创 5kyu—Rot13
#include <stddef.h>#include <string.h>#include <ctype.h>#include <stdlib.h>char *rot13(const char *src){size_t i ,len = strlen(src);char *str = (char*)calloc( len+1, sizeof(char) ); for( i = 0; i < len; i++ ){ if( !i
2021-06-07 21:03:09
74
原创 6kyu—Consonant value
#include <string.h>int solve(const char *str_in) { size_t thissum, maxsum, i; thissum = maxsum = 0; for( i = 0; i < strlen(str_in); i++ ){thissum += str_in[i] - 96;if( str_in[i] == 'a' || str_in[i] == 'e' || str_in[i] == 'i' || str_in[
2021-06-07 20:20:20
93
原创 6kyu—Mexican Wave
#include <ctype.h>#include <string.h>#include <stdio.h>void wave(const char *y, char **target){ size_t len = strlen(y), i, j, f = 0; for( i = 0; i + f < len; i++ ) { const char *x = y; while( *(x + i + f) == ' ' )
2021-06-07 19:47:01
94
原创 6kyu—maze runner
#include <stddef.h>char *maze_runner(const int *maze, size_t n, const char *directions) { int start, line, column, current; for( start = 0; start < n * n; start++ ) if( maze[start] == 2 ) break;//找到起点 line = start / n; column =
2021-06-06 22:37:55
109
原创 6kyu—Encrypt this!
#include <stdlib.h>#include <stdio.h>#include <string.h>void toascii(char** a, char **b){ if( **b == '\0' ) return; char ch = **b; int sum = 1; while( ch != '\0' ) { sum*=10; ch/=10; } while( sum != 1 ) {sum/=10;*(
2021-06-06 20:00:41
93
原创 5kyu—Play with two Strings
#include <string.h>#include <stdio.h>#include <ctype.h>#include <stdlib.h>void handover (char ch, char *str){ for(size_t i = 0; i < strlen(str); i++) {if( ch == toupper(str[i]) ){ if( isupper(str[i]) ) str[i]+=32;
2021-06-06 16:06:38
111
原创 2021-04-24
Description码头上有-批货物,它们被摆放成了n摞,每摞的个数(高度)为di,并排成一排。现在包工头酋长想用一台特殊的搬运机, 用最少的次数,将这批货物全部取走。这台搬运机的工作原理是: - -次可以取走相邻几排最下面一层的所有货物。例如:当货物共有4摞,每摞高度分别为231 2时,我们可以采用如下策略使得总使用次数最少第一步:由于四摞货物是相邻的,取走这四摞货物最下面的一排货物,当前变为1 201第二步:此时第三摞货物取空,第一、二摞和第四摞不相邻,取走前两摞货最下面一排,当前变为01
2021-04-24 17:39:28
625
1
原创 7-5 表格输出 (5 分)
本题要求编写程序,按照规定格式输出表格。输入格式:本题目没有输入。输出格式:要求严格按照给出的格式输出下列表格:Province Area(km2) Pop.(10K)Anhui 139600.00 6461.00Beijing 16410.54 1180.70Chongqing 82400.00 3144.23Shanghai 6340.50 1360.26Zhejiang 101800.0
2021-04-24 14:15:04
98
原创 7-4 BCD解密 (10 分)
BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位。所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12。但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了。于是BCD的0x12被输出成了十进制的18了!现在,你的程序要读入这个错误的十进制数,然后输出正确的十进制数。提示:你可以把18转换回0x12,然后再转换回12。输入格式:输入在一行中给出一个[0, 153]范围内的正整数,保证能转换回有效的BCD数,也就是说这个整数转换成十六进制时不会出现A-F的数字
2021-04-24 14:09:52
43
原创 7-3 逆序的三位数 (10 分)
程序每次读入一个正3位数,然后输出按位逆序的数字。注意:当输入的数字含有结尾的0时,输出不应带有前导的0。比如输入700,输出应该是7。输入格式:每个测试是一个3位的正整数。输出格式:输出按位逆序的数。 #include <stdio.h>`int main(){ int n,p=1000,flag=0; scanf("%d",&n); while( (p/=10) >0 ){ if(n%10>0 || flag) {
2021-04-24 14:06:51
45
原创 7-2 然后是几点 (15 分)
有时候人们用四位数字表示一个时间,比如 1106 表示 11 点零 6 分。现在,你的程序要根据起始时间和流逝的时间计算出终止时间。读入两个数字,第一个数字以这样的四位数字表示当前时间,第二个数字表示分钟数,计算当前时间经过那么多分钟后是几点,结果也表示为四位数字。当小时为个位数时,没有前导的零,例如 5 点 30 分表示为 530;0 点 30 分表示为 030。注意,第二个数字表示的分钟数可能超过 60,也可能是负数。输入格式:输入在一行中给出 2 个整数,分别是四位数字表示的起始时间、以及流逝的
2021-04-24 13:51:01
44
原创 7-1 厘米换算英尺英寸 (15 分)
如果已知英制长度的英尺foot和英寸inch的值,那么对应的米是(foot+inch/12)×0.3048。现在,如果用户输入的是厘米数,那么对应英制长度的英尺和英寸是多少呢?别忘了1英尺等于12英寸。输入格式:输入在一行中给出1个正整数,单位是厘米。输出格式:在一行中输出这个厘米数对应英制长度的英尺和英寸的整数值,中间用空格分开。#include<stdio.h>int main(void){int foot=0,inch=0,cm=0.0;scanf("%d",&c
2021-04-24 13:34:35
93
原创 6kyu—Prize Draw
To participate in a prize draw each one gives his/her firstname.Each letter of a firstname has a value which is its rank in the English alphabet. A and a have rank 1, B and b rank 2 and so on.The length of the firstname is added to the sum of these rank
2021-03-27 12:59:09
172
原创 codewars —6 kyu —Are they the “same“?
Given two arrays a and b write a function comp(a, b) (orcompSame(a, b)) that checks whether the two arrays have the “same” elements, with the same multiplicities. “Same” means, here, that the elements in b are the elements in a squared, regardless of the o
2021-03-21 12:19:30
263
原创 codewars—5kyu。Integers: Recreation One
1, 246, 2, 123, 3, 82, 6, 41 are the divisors of number 246. Squaring these divisors we get: 1, 60516, 4, 15129, 9, 6724, 36, 1681. The sum of these squares is 84100 which is 290 * 290.TaskFind all integers between m and n (m and n integers such as 1 <
2021-03-21 12:00:41
226
原创 6 kyu —The Vowel Code
Step 1: Create a function called encode() to replace all the lowercase vowels in a given string with numbers according to the following pattern:a -> 1e -> 2i -> 3o -> 4u -> 5For example, encode(“hello”) would return “h2ll4”. There is n
2021-03-20 14:25:59
109
原创 codewars—6kyu —Longest Palindrome
Find the length of the longest substring in the given string s that is the same in reverse.As an example, if the input was “I like racecars that go fast”, the substring (racecar) length would be 7.If the length of the input string is 0, the return value
2021-03-20 14:23:38
165
原创 7kyu— Find the stray number
You are given an odd-length array of integers, in which all of them are the same, except for one single number.Complete the method which accepts such an array, and returns that single different number.The input array will always be valid! (odd-length >
2021-03-14 11:06:07
122
原创 7kyu— Deodorant Evaporator
This program tests the life of an evaporator containing a gas.We know the content of the evaporator (content in ml), the percentage of foam or gas lost every day (evap_per_day) and the threshold (threshold) in percentage beyond which the evaporator is no
2021-03-14 10:37:46
500
5
原创 codewars— Maximum subarray sum
The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers:maxSequence({-2, 1, -3, 4, -1, 2, 1, -5, 4}, 9)// should return 6, from sub-array: {4, -1, 2, 1}Easy case is when the list i
2021-03-14 09:28:22
109
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人