当前位置:网站首页>C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
2022-07-24 17:39:00 【eat_ sleep_ play( )】
Catalog
One 、 In left-handed string K Characters .
Two 、 Little Lele and Euclid ( Find the greatest common divisor )
3、 ... and 、 Print arrow pattern
Four 、 Civil service interview

One 、 In left-handed string K Characters .
Title Description :ABCDE Turn a character left to get BCDEA, Left handed two get CDEAB
How easy it is :
#include<stdio.h>
int my_strlen(char* str)// Find the number of characters
{
int count = 0;// Record the number of characters
while (*str != '\0')
{
count++;
str++;
}
return count;
}
void left_rotate(char arr[], int k)
{
int i = 0;
int len = my_strlen(arr);
for (i = 0; i < k; i++)
{
// Left hand character steps
//1. Save the characters to be rotated first
char tmp = arr[0];
//2. Move the remaining characters forward
int j = 0;
for (j = 0; j < len - 1; j++)
{
arr[j] = arr[j + 1];
}
//3. Store the previously stored characters into the empty bits of the array
arr[len - 1] = tmp;
}
}
int main()
{
int k = 0;
scanf("%d", &k);
char arr[] = "ABCDEF";
left_rotate(arr, k);
printf(" The result of left rotation :%s\n", arr);
return 0;
}Two 、 Little Lele and Euclid ( Find the greatest common divisor )
Title Description : Xiao Lele recently learned in class how to find the maximum common divisor and minimum common multiple of two positive integers , But he can't find the sum of the maximum common divisor and the minimum common multiple of two positive integers , Please help him solve the problem .
How easy it is :
#include<stdio.h>
int main()
{
long long a = 0;
long long b = 0;
long long comax = 0;
long long comin = 0;
long long k = 0;
scanf("%lld %lld", &a, &b);
k = a * b;
while (a && b)
{
if (a > b)
{
a = a % b;
}
else
{
b = b % a;
}
}
comax = a > b ? a : b;
comin = k / comax;
printf("%lld\n", comax + comin);
}3、 ... and 、 Print arrow pattern
Title Description : Utilization cycle . Use * Print arrow pattern
How easy it is :
#include<stdio.h>
int main()
{
int n, i, j;
while (scanf("%d", &n) != EOF)
{
for (i = 0; i < n + 1; i++) // Control the top half * Output (n+1 That's ok )
{
for (j = i; j < n; j++) // Control space output
{
printf(" ");
}
for (j = 0; j <= i; j++) // control * Output
{
printf("*");
}
printf("\n"); // Line break
}
for (i = 0; i < n; i++) // Control the lower half * Output (n That's ok )
{
for (j = 0; j <= i; j++)
{
printf(" ");
}
for (j = i; j < n; j++)
{
printf("*");
}
printf("\n");
}
}
return 0;
}Four 、 Civil service interview
Title Description : Civil servant interview on-site scoring . Yes 7 Examiner , Enter several groups of grades from the keyboard , Each group 7 A score ( Percentage system ), Take out the highest score and the lowest score , Output the average score of each group .( notes : There are many groups of input )
How easy it is :
#include <stdio.h>
int main()
{
int a = 0;
int max = 0;// Maximum
int small = 100;// minimum value
int sum = 0;
int count = 0;
while (scanf("%d", &a) != EOF)
{
if (a > max)// Determine the highest score
{
max = a;
}
if (a < small)// Determine the lowest score
{
small = a;
}
sum += a;
count++;// Counter
if (count == 7)// Counter =7 When the score represents a group, it can be calculated
{
printf("%.2f\n", (sum - max - small) / 5.0);
count = 0;// Reset
max = 0;// Reset
small = 100;// Reset
sum = 0;// Reset
}
}
return 0;
}5、 ... and 、 Young's matrix
Title Description :
There is a matrix of numbers , Each row of the matrix is incremented from left to right , The matrix is increasing from top to bottom , Please write a program to find out whether a number exists in such a matrix .
requirement : Time complexity is less than O(N);
How easy it is :
#include<stdio.h>
find_k(int arr[3][3], int k, int* row, int* col)
{
int x = 0;// That's ok
int y = *col - 1;// Column
while (x <= *row && y >= 0)
{
// The number to be found is less than the number in the upper right corner of the matrix
if (k < arr[x][y])
{
// Matrix column number minus 1
y--;
}
else if (k > arr[x][y])
{
// Matrix rows minus 1
x++;
}
else
{
// The number to be found is equal to the number in the upper right corner of the matrix - eureka
*row = x;
*col = y;
return 1;// eureka
}
}
*row = -1;
*col = -1;
return -1;// Did not find
}
int main()
{
int arr[3][3] = { 1,2,3,4,5,6,7,8,9 };
int k = 0;// The number to find
scanf("%d", &k);
int row = 3;// That's ok
int col = 3;// Column
int ret = find_k(arr, k, &row, &col);
if (1 == ret)
{
printf(" eureka , The subscript is :%d %d", row, col);
}
else
{
printf(" Can not find \n");
}
return 0;
}
边栏推荐
- [wechat official account H5] authorization
- 2022年最新浙江建筑安全员模拟题库及答案
- Memory allocation and recycling strategy
- DHCP relay of HCNP Routing & Switching
- Array learning navigation
- Huawei machine test - topic core test point
- nc 端口转发
- Two dimensional convolution -- use of torch.nn.conv2d
- One article of quantitative framework backtrader: understand indicator indicators
- The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
猜你喜欢

Dry goods | three sub domain name collection tools worth collecting

调整图像亮度的滚动条演示实验

通道的分离与合并

opencv自带颜色操作

Opencv has its own color operation

Eth POS 2.0 stacking test network pledge process

Atcoder beginer 202 e - count descendants (heuristic merge on heavy chain split tree for offline query)

Portfwd port forwarding

Tensorflow introductory tutorial (40) -- acunet

An example of using viewthatfits adaptive view in swiftui 4.0
随机推荐
C语言自定义类型讲解 — 结构体
ROC and AUC details of the recommended system
Can Lu Zhengyao hide from the live broadcast room dominated by Luo min?
【网络安全】网站中间件存在的解析漏洞
Class bytecode file
Pat class A - A + B format
The latest Zhejiang construction safety officer simulation question bank and answers in 2022
NPM install reported -4058 error
Today, I met a 38K from Tencent, which let me see the ceiling of the foundation
Portmap port forwarding
Transformer structure analysis -- learning notes
Reptiles and counter crawls: an endless battle
快速完成intelij idea的单元测试JUnit4设置
Canvas from getting started to persuading friends to give up (graphic version)
[waiting for insurance] what does waiting for insurance rectification mean? What are the rectification contents?
数论整除分块讲解 例题:2021陕西省赛C
NATBypass 端口转发
微信朋友圈的高性能复杂度分析
生信常用分析图形绘制02 -- 解锁火山图真谛!
键盘输入操作