0 喜歡 0 不喜歡
1.3k 瀏覽

Write a program that reads a string of up to 100 characters, and if its length is less than three characters, it should force the user to enter a new one. Next, the program should read a character and check if the string contains the input character three times in a row. The program should display the position of the first triad found.

Sample input:

fg
DuplicateThis
D

Sample output: 

Not found

 

Sample input: 

Deeeply
e

Sample output:

1

Sample input: 

Deeeppply
p

Sample output:

4
[考試] 最新提問 分類:Midterm |
ID: 24270 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 1.3k 瀏覽

11 個回答

0 喜歡 0 不喜歡
內容已隱藏
#include ****

#include ***** ** **

int main()

{
* * * * * *** * ** * ch, string[100];
******** ** ** * ** * * ** * i, len;
** * ** ***** * * ** *
****** * ** **** * * ** * ** * ** ***** **** *
*** *** * ** *** * * * ** *** ** * ******* ** = strlen(string);
** * * ** * * ** * * while(len<3);
* **** ** ** * * ****** ****** **** * *** * = getchar();
*** * * ******** ***** *** ** = 0; i <= len-3; i++)
* ** * * *** * ** ** ******* ** * * ** * * * == ch && string[i+1] == ch && string[i+2] == ch)
** * * *** * * * * * *** * **** *
*** * ** * ** * * ** ** * ** **** * ** **** *** * *** * *** * *** *** *** ******
* * * * *** * **** ** ** *** **** ** *** * * * * *** * 0;}
* * ** ****** * ** ** ** * found\n");
* ** *** * ** * *** ***** 0;

}
最新回答 用戶: (38 分)
0 喜歡 0 不喜歡
內容已隱藏
#include * * ** * ****

#include * * * ****



int main()

{
**** *** **** * ** ** ***** ** ch, string[100];
*** ***** ** * **** * i, len;
*** * * * * ***
** * * * * ** *** * **** * *** ** * *** **** **
* ******* * **** ** * *** ** * ** ** * **** = strlen(string);
* * * * * ** * * ** *** ** * while(len<3);
** * *** * ** * ** ****** * * * *** * * *** = getchar();
** ** *** ** ***** * * ** * = 0; i <= len-3; i++)
**** ** ** * * * * ** *** * *** ** *** ** * *** == ch && string[i+1] == ch && string[i+2] == ch)
** * *** * * *** *** * * * * * * * * **** * ** * * *
* * *** * * * * * *** ** **** * *** * *** ** * ** * * * * * *** *
* ****** * * * ** ** ** ** * * * * * * **** *** *** * * * * 0;}
**** * * **** ** * * *** ** found\n");
****** * * ** ***** **** 0;

}
最新回答 用戶: (38 分)
0 喜歡 0 不喜歡
內容已隱藏
#include * ** * ***

#include *** ** * ****

#define MAX_STR 100



int main(){
** *** ** * ** * ** ch, str[MAX_STR];
*** ***** * ** * * i, len;
* * ** ** * ** * * * ** ***
** **** * * **** ** *** ** **** ** * * * ** **
** * ** ** ** ******** * * * **** ** * * = strlen(str);
* ******** * ** * ** while(len < 3);


** * * ** * * ** * = getchar();


** * *** *** * *** = 0; i <= len-3; i++)
*** ** * * * *** *** * **** * * * == ch ** * * str[i+1] == ch && str[i+2] == ch){
** * ***** ******* * ** * ** * * * ** * ** * ****** ** *** **** ** *** * **
*** **** * *** * * ** * **** ** *** *** * ** ** * * * * ** ** * * * 0;
* ** *** * * **** * ** * * * **** ** ** *
*** * ** * * * * * *** * ** ** * *** *


**** ***** * * * **** * * 0;



}
最新回答 用戶: (20 分)
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>



char input[100];

int error();



int main(){


** * ** * * * * i;
* ** ** ** ** **** * * * * pos = -1;
** ** * * ** *** ** * * lenght = 0;
** *** ***** ** ** *** flag = 1;
** ** ***** * ** ** ** ** triad[10];
* ** ** *** * * *** * * * * * ** *** * input);
* ** ** *** * ** **** = strlen(input);
* *** * **** **** * ** * < 3){
* * * * * * ***** * * * * * **** **** *** * < 3){
* *** * ** ** * ** * * ** *** ** ** * *** *
*** ** * *** * ** ** ** * * * ** ** * * ** **
* ** * * *** * * *


* ** ** ** *** * * * * = strlen(input);
*** **** * ******* *** *** * ** * triad);


* ** *** * * * * * * * * ***** * ** * input);


*** * ** ** * * * ** * = 0; i < lenght; i++){
*** * * * * * * * ** ** ***** *** * * * * ** * *** == triad[0]){
* ** *** * * **** * * * ** ** * * * * * *** * ** ****** * == triad[0] && input[i+2] == triad[0]){
** * * ** * ** * * * * * *** *** * * ** ** * * *** * * * *** ** ** * ** ** ** * ** * = i;
*** * * * * *** * * * *** * * ** **** * * * * * * ** ** * * * ***** * * * * ** * * * * * ** * * *
** * ** ** ** * * ** * * ** ***** ** ** * * * ** * ** *** ********** * *
* * * ******* * ** * ** * ** *** * * ******
**** * ** ** * *****


** * ** ** * * ** ** * == -1)
* ** *** * * * * * * *** * ** ***** ** * ** ***** **** * found");
* * ***** * * * * * * *
** * ** *** ** ** **** * * * ****** ** * ** ** * * ** pos);
** * **** * ** ** * * * 0;

}



int error(){
* ***** * * * ** * **** * * **** input);

}
最新回答 用戶: (-188 分)
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>



char input[100];

int error();



int main(){


* * * * ** ** ** i;
* ** ** ** * ** * *** pos = -1;
* * * * * * * * *** lenght = 0;
*** * * * * ******* *** flag = 1;
*** **** ** ** triad[10];
** **** ** ** ** * ** * * **** input);
*** *** * ** **** ** ** = strlen(input);
* ** * ** * * ** < 3){
* **** ** * * * * * * ** **** ** * * ** ****** < 3){
*** * *** * * ** ** ** * * * * *** * * * *
** * ** *** * ** *** ** * ** **** * *
** * **** * **


** **** **** *** ****** ** * ** ***** triad);


* ** ** * ** * * * * * * i< lenght; i++){
** * *** * * * * ** * **** ** * ***** == triad[0])
**** * ***** * ** * * * * *** *** ** * * ** ** ** * *** * * ** * ** == triad[0] && input[i+2] == triad[0]){
***** * *** *** * ** ** * * *** ** ** * * * *** * **** ***** * * * * * ** * = i;
***** * * * ** ** * ** * * *** **** ** *** * ** * *** * * ** ** * * **** * *** * ** ** * *
** ** *** * ***** ** ** * ***** * * * *** *** **** **** *** * ** *
* * * * * * *


* ** * * * ** * == -1)
** * * * * ************* * ***** ** * **** * ** ***** found");
* * ** *** * * *** **
** *** * * *** *** * * * ** * * **** ** ** * *** ** ******* * ** pos);
* * * **** * * ** * 0;

}



int error(){
** * ** * ** * * ** * * * **** * * ** * input);

}
最新回答 用戶: (-188 分)
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>



char input[100];

int error();



int main(){


**** ***** * ** * ** **** i;
** ** ** * * * *** pos = -1;
*** *** *** * ** * * *** lenght = 0;
* * * ** ** * * ** ** * flag = 1;
* * ** **** ** * * * ***** triad[10];
* * ** ** * * * ** * * * * * * input);
** ** ** * *** *** ** = strlen(input);
* ** ** ********** * * ** < 3){
* * * * * * ** * * ** * * ** ******** **** ** < 3){
**** *** ***** * **** **** * * ** * * ********* * *
********* **** * * **** * * *
* * * * * * * * * * ** *


* * * *** * ** * * * **** ** triad);


* ** **** * *** * ** i< lenght; i++){
* * * * * * *** ***** * * **** *** * * * * *** == triad[0])
** * ** ** * ** * * ** ***** * ***** ** * ****** * * * * * * ** ** * ** * ** * == triad[0] && input[i+2] == triad[0]){
*** * * ** * ** ** * * *** **** ** * * * ** ***** ** *** *** ***** ** **** ** *** = i;
* ** ** ** * *** * * * * *** * * * ** ******** ** ** * ***** * * * * *
**** * * ** ** *** ** ** * ***** ***** * *** * * ** **** ** **
* * *** ** ** ** * * *


* * *** * *** * * ** * ** == -1)
* ** *** * *** ** *** ** ***** * *** * ***** * * ** ** found");
*** ** * * ** ** *
* * * * * * **** * **** ** *** * ** * *** **** ******* ** * * * pos);
* ** * * * * * ** 0;

}



int error(){
* * **** * ** **** * * ** ** **** * ** input);

}
最新回答 用戶: (-188 分)
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include * * * * ** **



char input[100];

int error();



int main(){


* * * ** * * * * * ** ** i;
*** ** * * * ** *** pos = -1;
* * * * *** * *** * * lenght = 0;
* ** * ** * * * flag = 1;
* *** * * * * **** * * * triad[10];
*** * **** * * * ******* * * **** input);
* * * * ** * ** **** * = strlen(input);
* *** **** ***** ** ** ** * < 3){
*** **** * ** **** ** * ** * * ***** *** * **** *
* ******* **** * ** ** *


* **** **** * * **** *** * ***** *** * * triad);
**** * * **** * * ** * *** * %s %s", input, triad);


* * * *** ** * *** * ***** i< lenght; i++){
* **** * * * ** * * * ** * * * * * ****** ** == triad[0]){
* * ** **** * *** * * * * * ** **** ** ** ** * ** * ** * * * ** ** ** ** == triad[0] && input[i+2] == triad[0]){
** * **** ** ** * ****** ** ** ** * ** ** * ** ** **** * * ** * ** ** *** *** ******* ****** *** * = i;
** * * * * *** * *** ****** * * * ** * * * *** *** * ** ** * * ** * * *** * *
* ** * ** * **** ** ** *** ** * *** * * **** * *** ******* *
* * * * * ** ** * *** *** * * *** **
*** * * *** ** * * * *


* ** * * *** * ****** * ** == -1)
* * **** * * * * * * * * *** * * ****** ** * * found");
**** * * ** *** *
* * * * * *** *** * * ** ** * ** *** * *** * * ** * pos);
* * * ****** ** * *** * 0;

}



int error(){
******** * * * ** * ** * * input);

}
最新回答 用戶: (-188 分)
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

#include <string.h>



int main()

{
* ** * * * *** * ** ch, str[100];
** ** * **** * ***** *** i, len;
* * * * *** * ** **** *

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

    }
* *** * ** ** * * ** * *** * ** **
*** * * ** *** * * ** ** *
*** ** ** * * *** * * i<=len-3; i++)
** **** * * * * * *** * *** * * * * * ** ******* * * * ** *** *** * ** **** **
** * * **** * ** * * * *** * *** ** * * **
** ** ** * ** ** * * *** ** * **** ***** * ** *** **** ***** **** ***** * ** * * i);
***** *** ** ** * * * **** * ** *** ** *** *** *** * * ** 0;
*** * * * * * * ** ** ****** ** *** * **
*** * ** ***** * ** ******* *** found\n");
*** ***** *** * ** ***** 0;

}
最新回答 用戶: (-48 分)
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include ***** ** *



char input[100];

void error();



int main(){


* * *** * *** * ** * i;
** **** ** *** * * * *** ** *** pos = 0;
* ***** ** **** * * ** lenght = 0;
* ** ** **** ***** * ** flag = 1;
* * ** ** * * * triad[10];
****** ***** * *** * * * * * * input);
* * * ** ****** * ** = strlen(input);
* ** * *** ** * * ** * * < 3){
** ** *** * * * * * ***** *** * **** * * * *
* ** ** * * ** ** ** *


* ** ** * * *** ** * * ** * **** triad);
* * ****** ** *** *** **** %s %s", input, triad);


****** * ** *** i< lenght; i++){
* * **** ** *** ** * * ** * * ** *** ** * *** * == triad[0]){
* *** ** ******* * ** * * ** ** ****** ** * ** * *** ******* ** * ** == triad[0] && input[i+2] == triad[0]){
* **** **** ** ******* * ** * ***** ** * *** **** * * *** ** ** * * * * * * * * *** * = i;
** ** ** * * *** * ****** **** *** * * * * * ** * *** * * *** ** *** * **** ** ***
* ** * * ** ** *** * * * * * * * *** ****** * * * *
* * *** * * * * ** * ** ** *******
* **** * *** * *


*** **** *** ** ** ** * == 0)
** ** *** * ** * * * *** * * *** ** **** ** * found");
** ** * ** *** * ** *
* * * *** ***** * * * * * *** ** * *********** * ** ** *** * * pos);
* * ** * * * ** ** 0;

}



void error(){
* * * **** * * ** * * * ** ** input);

}
最新回答 用戶: (-188 分)
0 喜歡 0 不喜歡
內容已隱藏
* *** * *** ** **** * *
* *** * *** * * *



int main(){





char c, s[100];



int i, len;



gets (s);





while ** *** **


* **** * * * ** ***** * (s);

}




** * * * *** * * = * *
* *** *** ** ** * * ** * * ***


***** * * * * (i=0 ; i * * *




** * ** * *** * * *** ** ** ** ** *** s **** ** **** ** s[i+2] ==c){
* ****** * **** * ** * ***** *** ****** * * * *** * ** * **
***** * *** ** * **** * ** **** *** * *** * ** **** 0;



}



}
*** *** ** * ** * ******* * *** ** ** * ***

return 0;}
最新回答 用戶: (-34 分)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.127.118
©2016-2025

相關問題

0 喜歡 0 不喜歡
13 回答
[練習] Coding (C) - 最新提問 4月 21, 2017 分類:Midterm |
ID: 24268 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 1.3k 瀏覽
0 喜歡 0 不喜歡
65 回答
[考試] 最新提問 4月 13, 2017 分類:Midterm |
ID: 23786 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 5.1k 瀏覽
0 喜歡 0 不喜歡
8 回答
[考試] 最新提問 4月 21, 2017 分類:Midterm |
ID: 24273 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 974 瀏覽
0 喜歡 0 不喜歡
4 回答
[考試] 最新提問 4月 21, 2017 分類:Midterm |
ID: 24272 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 693 瀏覽
0 喜歡 0 不喜歡
6 回答
[正常] 最新提問 4月 21, 2017 分類:Midterm | 用戶: thopd (12.1k 分)
ID: 24271 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 823 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶