1 like 0 dislike
12.8k views

A string p is a prefix of a string s if the leading characters of s are identical to p. For example, "abc" is a prefix of "abcde". Develop a function prefix that checks if a C string p is a prefix of another C string s.

p是s的前綴若s開頭的一段字串等於p。例如,"abc"是"abcde"的前綴。寫一個程式 判斷字串p是否字串s的前綴。

Example input 1:

abc
abcde

Example output 1:

abc is a prefix of abcde

 

Example input 2:

bc
abcde

Example output 2:

bc is not a prefix of abcde

 

[Exam] asked in Final Exam
ID: 42299 - Available when: 2018-01-17 14:00 - Due to: Unlimited

retagged by | 12.8k views

37 Answers

0 like 0 dislike
Hidden content!
#include ******* **
#include *** * * **
int main()
{
***** ** ** * * A[99],B[99];
** *** * * ** *** * **** **** ** **
* ***** * **** *** * * * ** ****** ** *
**** *** ** * * * *** ***** ** * ** *
* *** * * * * * * * * * * * **** * * ** * **** * * is a prefix of %s",A,B);
* * * * * * * * **
*** ****** *** ** * ** ****** * * * * *** *** * * *** is not a prefix of %s",A,B);
* * * * ** * * *** * 0;
}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 0
-----------Re-judge-----------
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
** * * **** * *
*** * ** * ** *

int main(){
*** * ** * * * ** pre[100],str[100];
* * * * **** ****** **** *** * ** *******
* ** * * * flag=1;
** * * *** * * ** * * * ** * ***
* * ** * * ** * *** *** ****** ** ** * * **** ** flag=0;
** * * ****** * ***
* * * **** ** * * * * printf("%s is a prefix of * ***** * ***
* ** ** ** * ** **** * printf("%s is not a prefix of * ** *** *
*** * * * ** * * *** * 0;
}
answered by (-116 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include * * ****** ** ** *
**** * ****** * * ** *

int main()
{
** * * * *** *** ** **** **** * **** ** **
* * * * * * ** * **** ** 0;
}
answered by (-108 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>

int main() {
* **** ** *** ** * * ** * a[100], b[100];
** * **** *** *** ** * i,j,len,re=0;

* ** * *** ** * ***** **** **** *** {
* ** *** * *** ** * ** *** ** ** * * *** * * ** * ** *
*** * ***** *** **

**** * * * * ** **** **** * ******** ** * a);
* *** **** ** *** * * * ** * ** * * b);

* * ** * * * * * * **** * * * *
*** * * * ** ** ** ** ** * * * * * {
* *** ** ** * * * * ** ***** * *** * * *** * * * {
* ** **** ** ** * * * * ** * ** * ** *** * ***** *
** *** * **** ** **** * ** * *** * * **** * * * * * * **
* * ** *** * *** * * **** * * *
    }

** * **** * ***** * * {
** *** * *** ** * *** * * * ** ** * * is not a prefix of %s", a, b);
* ***** * ** *** *** * *
* **** * *** ** **** * if(re==0) {
****** * *** *** *** * * * ** ** ****** ** * ** * is a prefix of %s", a, b);
    }
}
answered by (-120 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
# include <stdio.h>
# include ** * ** **** * *
# include * ***** * * * **

int prefix(char p[],char s[])
{
* *** * *** * ** * * ** * **
* *** ** * ** * ** *** * *** **** **** 0;
** * ** ** *** ** ** * ** **** * * ** *
* * **** ** * * * * * * *** ** * * *** **** 1;
*** ** * *** * *** *
** ** * ** ** ** * *** ***** *** * * ** ** 0;
}

int main()
{
* ** *** ** * ** * ** p[999],s[999];

* *** * * ** * *** ** * * ******* * * ** *
* ** * * *** * * * * * ** **

** * * * * **** * * * * ** **
** *** **** * ** * * * **** ** *** * * * * *** is a prefix of %s",p,s);
** ** *** * ******* * **** ***
** ** * * ** **** ** **** **** * ** * ** * *** ***** * *** is not a prefix of %s",p,s);

* ** ** ** * *** * ** 0;
}
answered by (-16 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include ** ** * * **
#include **** * * * *
#include * ** * *
 int prefix(const char p[100],const char s[100])
 {
* ** ** * ** * ** ** ***** * * * ** *
** *** ** **** ** * * * *** * *** * *** * 1;
* * * ** ****** * * * * ** 0;
 }

int main()
{
*** ** ** * * * *** *** * ***** * **
* *** * ** * ** * ** * * * **
*** **** * ***** * ***** * ** * ** * ***** * **
** * * * * ***** **** *
* *** * ** ****** * * * is a prefix of * * * *
*** * **** * **** **
* * *********** ** * * *** * ***** * *** is not a prefix of * ** ** *



**** *** * **** ** * ** ** 0;
}
answered by (-196 points)
0 0
prog.c: In function 'main':
prog.c:9:8: warning: implicit declaration of function 'prefix' [-Wimplicit-function-declaration]
     if(prefix(p,s))
        ^~~~~~
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include * ***
#include <string.h>
int main()
{
****** * ** * * **** * a[100],b[100];
** ** * * *** * **** *** *** * %s",a,b);
* *** * *** * ** *** n=strlen(a);
* * *** ** * ** * * i,prefix = 1;

* **** ** * * *** * * * i<n; i++)
* * *** *** ** *** ****
* * * * * * **** * ***** **** ** * * **** * != b[i])
******* ** ** * ** ** ***** ***** * ** * ***
* ** ** ** **** * ****** * * * ** * * ** *** ** * * = 0;
** ** * *** * * ** ** * *** * ** * * * *** * ** ** ** * * *** * * is not a prefix of %s",a,b);
** * * * *** ** ** * * * * ***** ******** **** * ** * **** * * ****
* * ** * *** * ** ** * * *** *****
* **** * *** * **** * * * *

* * * ** **** **** *** == 1)
* *** *** ** * **** ** **** * * **** ** * * ** * * ** * ** * is a prefix of %s",a,b);

****** *** *** * * * * * ** 0;
}
answered by (-127 points)
0 0
prog.c: In function 'main':
prog.c:8:11: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     int n=strlen(a);
           ^~~~~~
prog.c:8:11: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:8:11: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.178.44
©2016-2025

Related questions

1 like 0 dislike
37 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42302 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 12.5k views
2 like 0 dislike
31 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42301 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 11.4k views
1 like 0 dislike
32 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42300 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 13k views
2 like 0 dislike
30 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42298 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 10.2k views
0 like 0 dislike
4 answers
[Exam] asked Jan 19, 2018 in Final Exam
ID: 43460 - Available when: 2018-01-20 09:00 - Due to: Unlimited
| 2.6k views
12,783 questions
183,442 answers
172,219 comments
4,824 users