0 like 0 dislike
2.1k views

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
[Exam] asked in Midterm
ID: 24270 - Available when: Unlimited - Due to: Unlimited
| 2.1k views

11 Answers

0 like 0 dislike
Hidden content!
#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;

}
answered by (38 points)
0 like 0 dislike
Hidden content!
#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;

}
answered by (38 points)
0 like 0 dislike
Hidden content!
#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;



}
answered by (20 points)
0 like 0 dislike
Hidden content!
#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);

}
answered by (-188 points)
0 like 0 dislike
Hidden content!
#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);

}
answered by (-188 points)
0 like 0 dislike
Hidden content!
#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);

}
answered by (-188 points)
0 like 0 dislike
Hidden content!
#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);

}
answered by (-188 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <string.h>



int main()

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

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

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

}
answered by (-48 points)
0 like 0 dislike
Hidden content!
#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);

}
answered by (-188 points)
0 like 0 dislike
Hidden content!
* * ****** * ***
** * * * ** ****



int main(){





char c, s[100];



int i, len;



gets (s);





while ** * ** * *


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

}




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


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




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



}



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

return 0;}
answered by (-34 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.130.71
©2016-2025

Related questions

0 like 0 dislike
13 answers
[Exercise] Coding (C) - asked Apr 21, 2017 in Midterm
ID: 24268 - Available when: Unlimited - Due to: Unlimited
| 2k views
0 like 0 dislike
65 answers
[Exam] asked Apr 13, 2017 in Midterm
ID: 23786 - Available when: Unlimited - Due to: Unlimited
| 7.8k views
0 like 0 dislike
8 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24273 - Available when: Unlimited - Due to: Unlimited
| 1.5k views
0 like 0 dislike
4 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24272 - Available when: Unlimited - Due to: Unlimited
| 1.1k views
0 like 0 dislike
6 answers
[Normal] asked Apr 21, 2017 in Midterm by thopd (12.1k points)
ID: 24271 - Available when: Unlimited - Due to: Unlimited
| 1.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users