# Konjaku writes Luogu (Continued)

## Write in front

Today, I went back and did what I couldn't write before. Since I can't do it, I'll record it;

## one

If the keyboard of the mobile phone of the old machine wants to press the English letter, it must press the number key more times. For example, if you want to press x, you have to press 9 twice. The first time you press W, and the second time you press w becomes x. Press the 0 key once and a space will appear.

Your task is to read several sentences that contain only lowercase letters and spaces, and find out how many keystrokes you need to press to type this sentence on your mobile phone.

requirement;

#### input

A line of sentences containing only lowercase letters and spaces, and no more than 200 characters.

### output

One integer per line represents the total number of keyboard presses.

#### Example

i have a dream

###### output

23

I was wrong when I first saw the question. I thought he wanted to make a letter that could be made by pressing it several times. Then he wrote it for a long time. Finally, he found that he read the question wrong and it was outrageous.

Of course, if you understand this problem, it's very simple. Simulate it directly and save it in the array every step, such as this

```int a[27]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4,1};
```

Array subscripts are directly implemented with letters. For example, 0 can be implemented with a [i] - [a '. Note that a[i]=a

Of course, you can't do this with spaces, so you have to list them separately;

Here is the code

```#include<stdio.h>
#include<string.h>
int a[27]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4,1};
int main()
{
char b[201];
int cnt=0;
gets(b);
for(int i=0;i<strlen(b);i++)
{
if(b[i]>='a'&&b[i]<='z')
{
cnt+=a[b[i]-'a'];
}
if(b[i]==' ')//Pay attention to the space!!!
{
cnt+=a[26];
}
}
printf("%d",cnt);
return 0;
}
```

## two

honoka has a two key keyboard.

One day, she typed a string with only these two characters. When the string contained VK, honoka especially liked the string. Therefore, she wanted to change at most one character (or nothing) To maximize the number of VK occurrences in this string. Given the original string, please calculate the maximum number of VK occurrences in this string (VK is considered to occur only when V and K are exactly adjacent.)

requirement

#### input

The first line gives a number n, which represents the length of the string.

The second line gives a string s.

#### output

The first line outputs an integer representing the answer.

#### Sample

```2
VK
```
###### output
```1
```

Link [P3741 honoka's keyboard]( P3741 honoka's keyboard - Luogu | new ecology of Computer Science Education (luogu.com.cn))

In fact, this question is to judge whether there is K behind V; then judge whether there is VV or KK;

The key is that it can only be changed once. We only need to judge where it appears for the first time, and it can not affect the previous VK;

The code is as follows:

```#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
char a[101]={0};
int i,flag=1;
//for(i=0;i<=n;i++)
//{
scanf("%s",a);//Be careful not to use for; it will read '\ n', which is difficult to handle
//}
int cnt=0;
for(i=0;i<n;i++)
{
if(a[i]=='V'&&a[i+1]=='K'){
cnt++;
a[i]='M';  //In order not to affect the direct replacement of him;
a[i+1]='M';//ditto
}

}
for(i=0;i<n;i++)
{
if(a[i]!='M'&&a[i]==a[i+1])//Pay attention to judge M;
{
cnt++;
break;
}
}
printf("%d",cnt);
return 0;
}
```

# three

You need to develop a word processing software. At the beginning, enter a string (no more than 100 characters) as the initial document. You can think that the beginning of the document is the 0th character. You need to support the following operations:

• 1 str: followed by insert, insert the string str after the document, and output the document string.
• 2 a b: intercept the document part, keep only b characters from character a in the document, and output the string of the document.
• 3 a str: insert the fragment, insert the string STR before the a character in the document, and output the string of the document.
• 4 str: find the substring, find the first position of the string str in the document and output it; if not, output - 1.

In order to simplify the problem, it is specified that the initial document and str in each operation do not contain spaces or line breaks. There will be q(q\le100)q(q ≤ 100) operations at most.

nothing

nothing

## Input and output samples

Enter #1

```4
ILove
1 Luogu
2 5 5
3 3 guGugu
4 gu
```

Output #1

```ILoveLuogu
Luogu
LuoguGugugu
3
```

Link [P5734 [Shenji 6. Example 6] word processing software]( P5734 [Shenji 6. Example 6] word processing software - Luogu | new ecology of Computer Science Education (luogu.com.cn))

This question is really outrageous. I didn't think of a good way anyway. I can only come to if else one by one. Of course, I can also switch

I refer to dalao's code;

as follows

```#include<stdio.h>
#include<string.h>
int main()
{
int n,m,l;
scanf("%d",&n);
char a[100];
char c[100];
char b[101];
scanf("%s",a);
int i;
while(n--)
{
scanf("%d",&l);
{
if(l==1)
{
scanf("%s",b);
int len=strlen(a);
for(i=len;i<len+strlen(b);i++)
{
a[i]=b[i-len];
}
a[i]='\0';
printf("%s\n",a);
}
else if(l==2)
{
int start,end;
scanf("%d %d",&start,&end);
for(i=start;i<start+end;i++)
{
a[i-start]=a[i];
}
a[end]='\0';
printf("%s\n",a);
}
else if(l==3)
{
int start;
scanf("%d",&start);
scanf("%s",b);
int len2 = strlen(b);
int len  = strlen(a);
for(i=len;i>=start;i--)
{
a[i+len2]=a[i];
}
//printf("%s\n",a);
for(i=start;i<len2+start;i++)
{
a[i]=b[i-start];
}
a[len+len2]='\0';
printf("%s\n",a);
}
else{
scanf("%s",b);
int len=strlen(a);
int len2=strlen(b);
int j;
int ans=-1;
for(i=0;i<len;i++)
{
for(j=0;j<len2;j++)
{
if(b[j]==a[i+j]){

continue;
}
else{
break;
}
}
if(j==len2){
ans=i;
break;
}
}

printf("%d\n",ans);
}
}
}
return 0;
}
```

# end

Tags: C

Posted on Mon, 29 Nov 2021 11:52:53 -0500 by Trafalger