Winter vacation practice of freshman last semester

A - identical test

The teacher hates it when someone plagiarizes in the exam. Since the electronic marking, it is much easier for teachers to find the same papers. As long as they input the answers of two people into the computer, compare them character by character, and find out the same positions at a glance.

Input format

22 lines, each line contains a string of characters (no longer than 200200).

Output format

11 lines, containing several numbers separated by spaces, indicating where the same characters appear.

Sample Input

I am  suantoujun.
I am  huayemei.

Sample Outpu

1 2 3 4 5 6 8 9
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
	int i = 0;
	char a[200], b[200];
	gets(a);
	gets(b);
	while (a[i] != '\0' && b[i] != '\0')
	{
		if (a[i] == b[i])
			printf("%d ", i+1);
		i++;
	}
	return 0;
}

B - initial capital

For all words in a string, if the first letter of the word is not uppercase, the first letter of the word is changed to uppercase. In the string, words are separated by white space characters, including space (''), tab ('\ t'), carriage return ('\ r') and line feed ('\ n').

Input

Enter a line: the string to be processed (length less than 80).

Output

Output one line: converted string.

Sample Input

if so, you already have a google account. you can sign in on the right.

Sample Output

If So, You Already Have A Google Account. You Can Sign In On The Right.
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
	char a[80];
	int i=1;
	gets(a);
	if (a[0] >= 'a' && a[0] <= 'z')
		a[0] = a[0] - 32;
	while (a[i + 1] != '\0')
	{
		if ((a[i] == ' ' || a[i] == '\t' || a[i] == '\r' || a[i] == '\n') && (a[i + 1] != ' ' && a[i + 1] != '\t' && a[i + 1] != '\n' && a[i + 1] != '\r'))
		{
			if (a[i + 1] >= 'a' && a[i + 1] <= 'z')
				a[i + 1] = a[i + 1] - 32;

		}
		i++;
	}

	puts(a);
	return 0;
}

C - case conversion

Read in some strings and convert lowercase letters into uppercase letters (other characters remain unchanged).

input

The input is multiple lines, and each line is a string. The string is only composed of letters and numbers, and the length does not exceed 80. Input ends with "End of file".

output

For each line of input, the converted string is output.

Input example

Hello
ICPC2004
12345abcde

Output example

HELLO
ICPC2004
12345ABCDE

Tips

The condition "scanf ('% s', STR) = = 1" can be used to judge whether the input ends. If this condition is false, enter end (for this question).

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	char str[80];
	int i = 0;
	while(scanf("%s", str) ==1)
	{
		for (i = 0; str[i] != '\0'; i++)
			if (str[i] >= 'a' && str[i] <= 'z')
				str[i] = str[i] - 32;
		printf("%s\n", str);
	}
	return 0;
}

D - Digital inversion

Given an integer, please reverse the numbers in each bit of the number to get a new number. The new number should also meet the common form of an integer, that is, unless the given original number is zero, the highest digit of the new number obtained after inversion should not be zero (see example 22).

Input format

Enter a total of 11 ^ lines, an integer ^ NN.

Output format

Output a total of 1 line, an integer, representing the new number after inversion.

Data range

-1,000,000,000 \le N \le 1,000,000,000−1,000,000,000≤N≤1,000,000,000.

Sample Input

123

Sample Output

321

Sample Input 2

-380

Sample Output 2

-83
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int num1=123, num2=0;
	int g = 1,n=10,wei=0,i=0;
	scanf("%d", &num1);
	if (num1 < 0)
	{
		g = -1;
		num1 = -num1;
	}
	while (num1!= 0)
	{
		wei = num1 % 10;
		num2 = num2 * n + wei;
		num1 /= 10;
	}
	num2 = num2 * g;
	printf("%d", num2);
	return 0;

}

E - delete word suffix

Given a word, if the word ends with an er, ly or ing suffix, delete the suffix (the title ensures that the length of the word after deleting the suffix is not {00), otherwise no operation will be carried out.

Input format

Enter a line containing one word (there is no space in the middle of the word, and the maximum length of each word is 3232).

Output format

Output the words processed according to the topic requirements.

Sample Input

referer

Sample Output

refer
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
	int n;
	char a[32];
	scanf("%s", a);
	n = strlen(a);
	if (n > 2 && a[n - 1] == 'r' && a[n - 2] == 'e') a[n - 2] = '\0';
	if (n > 2 && a[n - 1] == 'y' && a[n - 2] == 'l') a[n - 2] = '\0';
	if (n > 3 && a[n - 1] == 'g' && a[n - 2] == 'n' && a[n - 3] == 'i')a[n - 3] = '\0';
	puts(a);

}

F - judge whether the string is palindrome

Enter a string and output whether the string is palindrome. Palindromes are strings that are read in sequence and read backwards.

Input format

The input is a line of string (there is no blank character in the string, and the length of the string does not exceed 100100).

Output format

If the string is palindrome, output "yes"; Otherwise, output "no".

Sample Input

abcdedcba

Sample Output

yes
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
	int n=0,i=0;
	char a[100];
	gets(a);
	n = strlen(a);
	for (i = 0; i < n / 2; i++)
	{
		if (a[i] == a[n - i - 1])
			i++;
		else
			break; 
	}
	if (i >= n / 2)
		printf("yes\n");
	else
		printf("no\n");
}

H - dictionary order

Give you two different strings. If the dictionary order of the first string is less than that of the second string, output YES. If the dictionary order of the first string is greater than that of the second string, output NO.

Input

Two lines. The first line is a string, and the second line is a string. Ensure that the length of the string does not exceed 10000. Ensure that two strings are not exactly equal.

Output

If the dictionary order of the first string is less than the second string, YES is output. If the dictionary order of the first string is greater than the second string, NO is output.

Sample Input

abc
abe

Sample Output

YES
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
	int i;
	char a[10000]={0}, b[10000]={0};
	gets(a);
	gets(b);
	i = strcmp(a, b);
	if (i < 0)
		printf("YES");
	else
		printf("NO");
	return 0;

}

I - verify substring

Enter two strings to verify that one string is a substring of the other.

Input format

Enter two strings, each on one line, with a length of no more than 200200 and no spaces.

Output format

If the first string {s_1s1 , is the second string , s_2s2 , then "(s1) is substring of (s2)";

Otherwise, if the second string s2 is a substring of the first string s1, output "(s2) is substring of (s1)";

Otherwise, output "No substring".

Sample Input

abc
dddncabca

Sample Output

abc is substring of dddncabca
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
	int n1 = 0, n2 = 0, i = 0,j=0,g=0;
	char a[200], b[200];
	scanf("%s", &a);
	scanf("%s", &b);
	n1 = strlen(a);
	n2 = strlen(b);
	if (n1 > n2)
	{
		for (i = 0; i <= n1; i++)
		{
			for (j = 0; j < n2; j++,i++)
			{
				if (a[i] == b[j]);
				else break;
			}
			if (j == n2)
			{
				printf("%s is substring of %s",&b,&a);
				g = 1;
			}
				
		}
		
	}
	if (n1 < n2)
	{
		for (i = 0; i <= n2; i++)
		{
			for (j = 0; j < n1; j++,i++)
			{
				if (b[i] == a[j]);
				else break;
			}
			if (j ==n1)
			{
				printf("%s is substring of %s",&a,&b);
				g = 1;
			}
		}
	}
	if (g == 0)
		printf("No substring");

}

J - substring lookup (search result timeout)

This is a template question.

Given a string , AA , and a string , BB, find the number of occurrences of , BB , in , AA ,. The characters in AA , and BB , are English capital letters or lowercase letters.

AA , BB , at different positions in AA , can overlap.

Input format

The input consists of two lines: String AA , and string BB , respectively.

Output format

Output an integer indicating the number of occurrences of , BB , in , AA ,.

Sample

InputOutput
zyzyzyz
zyz
3

Data range and tips

1 \ Leq length of A,B1 ≤ A,B \ leq 10 ^ 6 ≤ 106, AA, BB only contain upper and lower case letters.

#include<stdio.h>
#include<string.h>
int main()
{
	char a[1000005]={0}, b[1000005]={0};
	int i, j,count=0,n1=0,n2=0,g;
	scanf("%s", a);
	scanf("%s", b);
	n1 = strlen(a);
	n2 = strlen(b);
	for (i = 0; i <= n1-n2; i++)
	{
		g=i;
		for (j = 0; j < n2; j++,g++)
		{
			if (a[g] == b[j]);
			else break;
		}
		if (j == n2)
			count++;
	}
	printf("%d", count);

}

Keywords: C

Added by Jurge on Mon, 10 Jan 2022 13:12:20 +0200