0 like 0 dislike
8.9k 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: 23786 - Available when: Unlimited - Due to: Unlimited

reshown by | 8.9k views

65 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



int main()

{
*** *** * * *** * ** * ** len,i;
* * * **** *** * ** A[100],B[10];
** * ** * ** * **** * *** **
** ** * * * ** ** ** **** * * * ** * **** *
* * ***** * * ** * **
** *** * **** ** * ** * i<len; i++)

    {
**** * ** * * ** ** ** **** *** * *** * * && A[i+1]==B[0] && A[i+2]==B[0])
* * * * ** * * * * *** ** * ** * *
** *** * ******* **** ** * * *** * ** ** * ** *** ** ****
** ** *** **** * *** * * ****** * ** * *** *
** * ** *** * * * *
** * * * * * ** ****** * *
**** * **** * * * ** **
** *** * ****** ** ***** * * ** *** ** *** * **** * * * *
** ** ** * ****
****** * * ** *** *
** * * **** ****** * * * * **** ** ** found");
** * ** ** * * * * 0;

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

#include<stdlib.h>

#include<string.h>

int main ()

{

  char a[130],w,x;

  int i,j,l,s=0;

  do

  {

   gets(a);
* * **** *** * * * * *

  }while(l<3);



scanf("%c",&w);
*** * * ** **** * **

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

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

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

    }
* * * **** **
** * * * * **** * *** * ** * ******* ** * ** ** ** * found");

}

else **** ** * * **** * * *****

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

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

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

    }
**** ** * * **** ***
** ****** ** **** *** **** * * * * * ** ** * ** ***** * found");

}

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

#include<string.h>



int main(void)

{
***** * * ** * * **** ** ch[100]={"0"},check;
** ****** ** *** * *** ** i,count=0;


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


* * * ** * * ** * * * *** %c",&check);


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

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

    }
* ** * * * * *

    {
** *** ** ** **** * ** ** *** ** * ** ******* **** * found");

    }
** ******* ** ** * * 0;



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

#include<string.h>



int main(void)

{
* ** * **** **** * * * ****** * ** * ** * * * * **** *
* ** * *** * ** ** i,count=0;



    do{
****** *** ** ***** * * ** *** ** * *** ** * * * ** * * *
* ** ** * ** * * * ***** **** *** ***


* * ** ** *** * ** **** * *** * %c",&check);


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

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

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

    {
***** *** *** * * * * ** *** * ** *** * * * * ** ** found");

    }
** ** *** * ** ***** 0;



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

#include<string.h>



int main(void)

{
* * ** *** * *** * *** ** ***** * * * * * ** ** * * ***** *
* *** ** **** * i,count=0;



    do{
** *** * ** ** * ** * * ** * *** * *** ** * **
* * * * *** ** *** * *** * **


*** *** *** ***** ** ** ** * %c",&check);


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

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

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

    {
* ** **** * * * ***** * ***** * * * **** * ** * found");

    }
**** * * * ** **** * ** 0;



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



int main()

{
* ***** ** * **** input[100], ch;
**** * * ***** *** ** i = 0, p = 0;
** ** *** **** * (;;)
* **** *** * ** ******* ***
***** * **** * ** * * * * * *** ** ** ** ** * * * &input);
** * *** * ********** * * *** ** ** **** *** (strlen(input) >= 3)
***** ** * *** * ***** * ** ***** * * * ** *** * * * ** *
* * *** * * * ** ** * ** **
*** *** ***** *** * *** ** %c", &ch);
* * * ** ** * * (i = 0; i < strlen(input); i++)
** ** * ** *** *
** ** * * *** * ** ** **** ** * ** * ((input[i] == ch) && (input[i+1] == ch) && (input[i+2] == ch))
*** ** ** ** * *** * ********** * * * ***** **** * ** *** = i;
*** * ***** ** * ** *****
*** ** * * ** *** **** * * (p == 0)
* **** ** * * * * *** ** * * * * * ** * *** * found");
* ** *** *** * *** **
* * *** * * * * * ** * ** * ** * * * * ** ** p);
** * *** ******* * * * ***** 0;

}
answered by (-218 points)
0 like 0 dislike
Hidden content!
#include * ** * *** ****

#include ** *** ** *



int main()

{
***** ** ** * * **** a[100], b;
* *** **** **** *** *** i;
*** ** * ***** ** * **** ***** *** * * ** * * a), **** ** *


* * * *** * * ** * * * ** %c", &b);


* ** ** * ** * ***** * * * * * i++)
* ** ** * ******* * *
* ****** ** * * ** * * ** * ***** ** *** * && a[i+1]==b ** * * * a[i+2]==b)
* * ** ** * ******* * * * ** *** ** *** * * * * * ** * * * ** ** i); i = -1; break;}
***** *** **** ** ** ****
** * * ** * ** ** * * * != -1) **** ** found");


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

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



int main(){
* * * * ** *

** * * * * char * ** **
* *** * char c[1];
* **** * * while(1){
*** *** * *** * ******** * ** ** * * ** * * *
* * ** * * * int len = * ** * **
***       if(len < 3) continue;
* * ** * * * ** * ** * * * * * * **** ** **
** * ** ** ** ***** *** int i;
* *** ** ** * * * ** * **** * * ** *
* * * ** * * ** * * * ** ***** ***** * ** == c[0]){
** ** * * * ** **** * * *** * * *** ** * * * * ** * ****
** * ** * ** * * * * * * **** * * ** ** * * return 0;
* * * * ** * ** * }
* * *** *** }
*** *** * * * * * * ** **
**** * * * }

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



int main(){
** ** *

* ** ** char **
*** ** * char c[1];
******* * ** * while(1){
** * ** * * * **** **** * ** * * ***** *
**** ** * **** ** * int len = * * *****
* ** ***   ** if(len < 3) continue;
* * ** * * * ****   ***** * **** * ****
* ** *** ** *** * ** ** int i;
*** ** * ** * * ** * * *** * *** * * * **
** ** * * ** * ***** * *** * ** * == * ** * * break;
** * *** * ****** * ***** }
* * * ** **** * * ** ** ** **
** ** * }

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

#include <stdlib.h>

#include <string.h>



int main()

{
** **** * *** * a[100];
** * * * ** *** * * * * ** find;
*** * ** ** * ** * i;


* * ** **** * * ****
* ** * ** **** * * * * **** * * * *
** ** **** * * ** * ** (strlen(a)<3);


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


**** ** * * ** * * i<=strlen(a)-3; i++)
* * * * * * * ******
* * * * ***** ********** ** * * *** ** (a[i]==find && a[i+1]==find && a[i+2]==find)
** * * *** **** * * ***** **** *** * **** * ** ****
* ** *** * *** * ** ** * ** * * ***** **** *** ** * * ***** ****** * * ***** ***
** * ** *** * ** **** ** ** * ** * * ***** * * * **** ** **** ** * **
** * ** * * ** * ** * * ** * ** * * * * * **
****** * ** * *********** ** *** ** * ***** * * ** * * * if (i>=strlen(a)-3)
** *** * * * ** * ***** * ** ** * * *** *
** * * *** * * ** ** * *** ***** **** ** ** ** ***** *** * * ** ** ** found");
* * ** * ** ** * ** * *** * ** * * * ** *** * * ** * * * * ****
* ** * ** * *** * ******* * ** ** * *** *** **

    }
* * * ** ****** * ** * 0;

}
answered by (-190 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.120.75
©2016-2026

Related questions

0 like 0 dislike
11 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24270 - Available when: Unlimited - Due to: Unlimited
| 2.4k views
0 like 0 dislike
13 answers
[Exercise] Coding (C) - asked Apr 21, 2017 in Midterm
ID: 24268 - Available when: Unlimited - Due to: Unlimited
| 2.4k views
0 like 0 dislike
47 answers
[Exam] asked Apr 13, 2017 in Midterm
ID: 23784 - Available when: Unlimited - Due to: Unlimited
| 6.6k views
0 like 0 dislike
8 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24273 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
0 like 0 dislike
4 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24272 - Available when: Unlimited - Due to: Unlimited
| 1.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users