当前位置:网站首页>1077 kuchiguse (20 points)
1077 kuchiguse (20 points)
2022-06-30 14:55:00 【Xue Dongjing】
1077 Kuchiguse (20 branch )
The question
give n Group string , Find the maximum common suffix of this group of strings . If there is no output ”nai".
Ideas
First invert all strings , Change the public suffix to the public prefix .
Then iterate over all the strings , Find public prefix .
The input string contains spaces , Input char Type character array cannot be used scanf("%s"), It can be used cin.getline(str,m),str This is the string array ,m Subtract one from the maximum number of characters entered ( The terminator at the end of the string will occupy a ). Also available string type , For input getline(cin,str).
string Type has string inversion function ,reverse(str,str+n) The length is n String inversion of .
and char You need to write an inversion function .
Pay attention to differences string and char Different input and output modes .
Code
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
char str[205][258];
void reverse(int n)
{
int len;
for(int i=n-1;i>=0;i--){
len=strlen(str[i]);
for(int j=0;j<len;j++){
str[i+1][j]=str[i][len-1-j];
}
}
}
void cmp(int n,int m)
{
int count=0;
bool flag=0,temp=0;
for(int i=0;i<m;i++){
for(int j=2;j<=n;j++){
if(str[j][i]!=str[1][i]){
flag=1;
break;
}
}
if(flag){
break;
}
count++;
}
if(count==0){
printf("nai");
}else{
for(int i=count-1;i>=0;i--){
printf("%c",str[1][i]);
}
}
}
int main()
{
int n,m=256;
scanf("%d\n",&n);
for(int i=0;i<n;i++){
cin.getline(str[i],257);
if(m>strlen(str[i])){
m=strlen(str[i]);
}
}
reverse(n);
cmp(n,m);
return 0;
}
边栏推荐
- 1133: output family and friends string
- [extensive reading of papers] multi modal sarcasm detection and human classification in code mixed conversations
- Matlab finds prime numbers within 100
- Programming exercises: special numbers (problem solving ideas + code implementation)
- How to program and process such parts?
- CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2
- V3 01_ Welcome
- 1031 Hello world for u (20 points)
- Working principle and fault treatment of cutting cylinder in CNC machining center
- 1105 spiral matrix (25 points)
猜你喜欢

August 24, 2021 deque queue and stack

CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015
![[buuctf] [actf2020 freshman competition]exec1](/img/af/22051a5feb3c1f6d7201a483bde127.jpg)
[buuctf] [actf2020 freshman competition]exec1

How to realize selective screen recording for EV screen recording

CCF Z-scan (full mark code + problem solving ideas) 201412-2

Clear the route cache in Vue

Svn password forgetting solution

Detailed explanation of settimeout() and setinterval()

Thinkphp5 log file contains trick

CCF date calculation (Full Score code + skill summary) February 2, 2015
随机推荐
Hbuilder most commonly used and full shortcut key set
Win10 backup backup shows that creating a shared protection point on the shadow failed
In situ merging of two arrays with two pointers
Matlab to find prime pairs within 100
PS dynamic drawing
[extensive reading of papers] multi modal sarcasm detection and human classification in code mixed conversations
Learn about data kinship JSON format design from sqlflow JSON format
2021-05-12
Double pointer circular linked list
Shift operator (detailed)
这种零件该怎么编程加工?
Steps for commissioning of vertical machining center
Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014
HD mechanical principle · classic dynamic drawing of mechanical design
1150 traveling salesman problem (25 points)
1132: stone scissors cloth
Searching for single element in dichotomy
PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
Matlab finds prime numbers within 100