当前位置:网站首页>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;
}
边栏推荐
- 2022 牛客暑期多校 K - Link with Bracket Sequence I(线性dp)
- 滚动条调整亮度和对比度
- C语言中的字符与字符串库函数的使用以及模拟实现
- 700. 二叉搜索树中的搜索-dfs法
- ansible自动化运维详解(五)ansible中变量的设定使用、JINJA2模板的使用以及ansible的加密控制
- Is it safe for qiniu to open an account?
- Getaverse, a distant bridge to Web3
- Baidu PaddlePaddle easydl x wesken: see how to install the "eye of AI" in bearing quality inspection
- 地表最强程序员装备“三件套”,你知道是什么吗?
- C语言实现静态版本的通讯录
猜你喜欢

Still using xshell? You are out, recommend a more modern terminal connection tool!

C语言实现静态版本的通讯录

Internship report 1 - face 3D reconstruction method

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

Analog electricity - what is the resistance?

Safety: how to provide more protection for pedestrians

Gan Development Series II (pggan, Singan)

OpenCV 图片旋转

邻接表的定义和存储以及有向图无向图的邻接存储

Baidu PaddlePaddle easydl x wesken: see how to install the "eye of AI" in bearing quality inspection
随机推荐
Memory allocation and recycling strategy
One article of quantitative framework backtrader: understand indicator indicators
干货|值得收藏的三款子域名收集工具
EF core data filtering
Stop littering configuration files everywhere! Try our 7-year-old solution, which is stable
图像像素的逻辑操作
C语言编程训练题目:左旋字符串中的k个字符、小乐乐与欧几里得、打印箭型图案、公务员面试、杨树矩阵
2022 ranking list of database audit products - must see!
awk从入门到入土(17)awk多行写法
DHCP relay of HCNP Routing & Switching
Getaverse,走向Web3的远方桥梁
[waiting for insurance] what does waiting for insurance rectification mean? What are the rectification contents?
Preliminary understanding of redis
Dry goods | three sub domain name collection tools worth collecting
portmap 端口转发
Canvas 从入门到劝朋友放弃(图解版)
In the morning, Tencent took out 38K, which let me see the ceiling of the foundation
2022 牛客暑期多校 K - Link with Bracket Sequence I(线性dp)
详解 Apache Hudi Schema Evolution(模式演进)
2022 Asia International Internet of things exhibition