0 like 0 dislike
1.3k 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 | 1.3k views

65 Answers

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)
* * * * ** ** * * **** * * * *** ** * ** * ***
** ** * * * *** ** * *** ******* ** * *** **** *** * ** ** * * ** * * *
* * ** * *** ***** * * ** * * *** ** * *** * * ** ** * * ***** * *
* * ** * * ** * ** * ******** * * ** **
** * * * **** ** ** *** ** *** * **
** ***** ***** * ** * * * *** * *** * ** * * *
** ****** * ** **** * *** ******* ****** * ** ** * ** ** **** ** * ** * **** * found");
* * ** * *** * * *** * *** *** * * ** * * * ** * * ** * ** *
** ** ************ *** * * ** * * ** * **
** * **** ** * ** ****
**** *** * * ** * * *********** 0;

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

#include<string.h>

#include<ctype.h>

int main()

{
** * * * * * ** ** * ** * s[100], find;
*** * * * **** * * * i, flag=0, pos;



    do{
* * **** * * *** ***** ** * * * ***
** * * * ** * * * * ** * * ** ***
* * * *** ** * *** * ****** *** * * *** &find);


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

    }


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

    }
* ** ** ** ** * ** if(flag>=3){
***** * * *** *** ** ********* **** * * *** * * * pos);

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

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

#include<stdlib.h>

#include<string.h>

int main()

{

    char a[100],found;

    int len=0,count=0,c=1,i,stop=0;
** * * * *** ** *** * *****
* ** * * ****** **** *** * ******* * * *** **
** * ** ** * ** *** ** * * ** *** *** ** * * *
**** * *** ** * * *** * *** * *** ** * ** * **
**** * ***** **** ** * **** * * * * * ** ** * * *** **** ** * ***

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

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

    }

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

}
answered by (-384 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)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <string.h>



int main()

{
* * * ** ** * ** word[100],compare[2];
* *** **** * * ** ********* length,i,count=0,pos,temp=1;
** *** * * * ***** *** * * ** * *** &word);


** *** ** * * * ** * * ** = strlen(word);


** * ** * ** * * *** *** *** * < 3)
* * * * * ** * * *
******* * * * * ** *** * *** * **** * ** * *** ********** * * &word);
** *** ** ****** ** **** * * ** ** * *** * * * * * = strlen(word);
* * * **** * * * * ** * *


* * * * ** *** ***** * * * * * ** * compare);


* * ** ** ** *** ** ** = 0; i < length; i++)
*** * **** * * ****
* ** * * * ** * ***** * * * * ** *** * * * * == compare[0])
** * **** * ** ** * * ** * * * * * * ** * * ** ***
* ** * *** * * *** * ** * * ***** * ** * **** *** * * * ** ** *
* * * * ** * * **** ********* ** * *******
** * * * * **** ** * * ** *** * ** * * *** == compare[0] && temp == 1)
** *** *** * * * ** * * ** *** *****
* ** ** * ***** ** * ** * * ** *** * **** * * * ** ** **** * = i;
** *** ** * * ** ***** ** * * * * * * * * * *** * ***** = 0;
* * **** * * * **** **** ** * * ** * ** **
** ** ** * * ***


* *** ** * * * *** ** * >= 3)
*** * * ** * * * * **
* * *** * * * * * * * ******* *** * * ***** * *** * * * pos);

    } else {
* ** ** ** * ** * ** *** *** ** * * ** ********** found");


*** * * * *****


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

}
answered by (-189 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)
0 like 0 dislike
Hidden content!
#include ** * * **



#include *** * ** * * *







int main()



{


*** ** *** ** * * ** * ch, str[100];


**** * * ** * * * * * * * **** 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 (-215 points)
0 like 0 dislike
Hidden content!
* * * * *** * ** *
* * *** * * * ***



int main()

{

char a[100],b[1];

int i,m=-1;



do

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

} * *** * *



scanf(" ** * *****


* * * * *

{
* ******** **** * ** *** *** **** * * * ** * b[0]==a[i+1] && b[0]==a[i+2])
* ** ** ** * ** * * **** ** ** * * * *
* ** * **** * * ***** * * ** ******* * * ** ** * *** ******** *****
*** * ** * *** **** *** * ** ** ** ** ** * **** * * * * ****** *
* * * * ** * * * ** * * * ****

}



if(m==-1)

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

}

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

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

#include * ** *



int main()

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

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

#include * * * **

#include <string.h>



int main()

{
* * * ** * **** * ** * ** txt[100], n;
* * ** * ** * * ** * i, found = 0, num;


** ** * ** * * ***
* ** * * *** * * * *
*** * * * * ** * * * ** * * ** * * ** *** *** * ** *
** * ** * *** **** * * while(strlen(txt) < 3);


* * **** ** ******* ***** *** ** * **** &n);


* ** * * * **** * **** ***** i<strlen(txt); i++)
** * * * * * ***
************ * * **** ** * ** * ** * * == n && txt[i+1] == n && txt[i+2] == n)
* * * ***** *** ** * *** ** *** ** **** *
* *** * *** *** *** * ***** * * * ** **** *** * **** **** = 1;
* ***** * **** * **** **** * * * * * ** ** *** ***** * **** * *** * * *
**** ****** * **** **** ** * ** ** ** * * **
*** * * **** **** * ***


***** **** * ** * *** ** **** == 1)
***** * ** **** ** * ** * * * **** * ** ** * *** * * ** **** *** i);
* * * ** ** * * *** *
* *** * * *** * * ** ** * * *** * * * * * * * ** found");


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

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

Related questions

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