0 like 0 dislike
1.5k views

Write a program that reads a string of up to 100 characters and displays it after remove all 'a' characters that exist at the beginning and at the end of the string. For example, if the user enters "aabbadaa", the program should display "bbad".

Sample Input 1:

aaTriHarda

Sample Output 1:

TriHard


Sample Input 2:

ResidentSleeper

Sample Output 2:

ResidentSleeper

 

[Exercise] Coding (C) - asked in C
ID: 22314 - Available when: Unlimited - Due to: Unlimited

edited by | 1.5k views

97 Answers

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

#include <string.h>



int main ()

{
* *** * ** ** *** s[100];
* * *** *** * ** * * i, pos1=-1, pos2;


* ** * ** * **** *** * * ** ** *** s);
*** ******** * **** *** *** = strlen(s);




** * * ** ***** * ** ** * for when there is no a at the start of the string
* **** * *** ** ** ** *** ** * * ** *

    {
* * * *** ** * ** ** ****** * *** * * ** (s[i]== 'a')
* * * * ** ** ***** * * ** ** * ** ** *
** * * * * ** * * * ** *** ** ******* * **** ** * ** * ** * **
***** ** * ** * ** ***** *** ** * ** * ** *
*** * ***** * ** * * ***** * ** * *** *
* * * * * *** ** ** ******** *** ** ** ** **
* * * ***** *** * ** *** **** ** * * * * * ***** ** ******* *** *
* ** *** ** * ** * *** *** ******** ** * **

    }


* * * ** **** ***** ** ** * for when there is no a at the end of the string
* * **** * *** ** **** *** * ***** * **

    {
* * ** ********* *** ** **** * * ** * ** * * (s[i]== 'a')
**** *** ****** *** ** ***** * *** * ** * ** **
***** * * * ** * ** *** * * * ** * *** * * **** * *
** * ***** * ** * * ********** ** ** **
* * * * * ***** ***** ** **** ***** *** *****
** *** ** *** ** * * ** * ***** * * ***
* * ** ** * ***** *** * * ** *** ******* **** * ** * ** ** *
** **** **** * * * * ** *** * ** * *

    }


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

    {
** * * * ** * ** ** * * ** **** * * * * *** ** * * ** s[i]);
** ** *** * * ** * * ** *
* ** * * * ** ** *** **** 0;



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

#include <string.h>



int main ()

{
* * * ******** * ** **** * s[100];
** * *** * * **** ** * i, pos1=-1, pos2;


** * ****** ** * * ** ******
* **** * *** *** * * ** * = strlen(s);




** * ** ******** for when there is no a at the start of the string
*** * *** ****** *** * ** * ** * * **

    {
* ******** *** ** * * **** * * ** ***** * * * (s[i]== 'a')
** ** ** ** **** * ** *** ** * * * **
* * * * *** * ** * ******* ** ** ** * * ****** ****
* * * **** * * * * ** * *** *
*** * **** * ** ** *** * * * ** ** ** * *
* ** ** ** * ** * * *** ** * ****** ** * ****
******* * *** **** * * * * ** *** *** * * ** * * ** * ** ** *** ** ***
* ** * * * * ** * **** * *** * *

    }


******* * * * ** * **** ** * for when there is no a at the end of the string
*** * * **** * ** * * * **** * * *
* **** * **
* ** **** *** *** ** *** ** ** * ******* (s[i]== 'a')
*** * * * ** * ** * * * ** *** * * *
**** *** * * ** * ******* * * * *** * ***** * ***** **** ** ** * *** ** ***
* * * ** * ** * * *** ** *** *
* * * * ** * ** ** ** * * *** ** **** * * *
* ** ** *** ** ****** * * ** **** * * * ** ** * *
* * * * ** * * * **** *** *** * * ** ** *** * * * ** *** * * *
** ** ** * *** * ** * * ** ** *** * * ****

    }


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

    {
* *** **** ** * * * ** ** * * * ** * * * * * *** * *** *** * s[i]);

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



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



int main ()

{
** * ** * * ** * * s[100];
*** * * ** *** * * * * * * i, pos1=-1, pos2;


* *** * * * * * ** **** * **
* * * ** ** ****** * * = strlen(s);




**** * ** ** ** * *** ***** for when there is no a at the start of the string
*** * ** ** * ** * * *** * *** ** **

    {
* ** ** * * ** ** ** *** * ****** * * ** ** * (s[i]== 'a')
* * * *** ** * *** * * * * ***** *** * *
** * *** * ** * ** * * ** ** * * ********* ** * * * ** * ****** ** * **
* * * * * * * * *** * * * * *** ** **
* * * *** **** ** *** ** * ** *
* *** * ** * ** ** ********** ** * *** *** **** *
* **** **** * ** ** * ** ** * * *** *** **** * * * * * ** * * ** *** ***
********* ** ** ** **** * ***** * ** * * ***

    }


* ** * **** **** * ** * *** for when there is no a at the end of the string
* * ** * **** ** *** *** **** ** * *

    {
* ** * **** * ** * * ****** * * * * * * (s[i]== 'a')
*** *** **** * *** *** ** ** * ** ** * *
*** ***** **** ** *** **** * * * **** ** * * ** *** * **** ** ** **** ** *
* * ***** * * ** ** *** * **** * * **
* ***** ** ** * * * ** * * ** ** * * * ** **
* * * ** * * *** * ** * ** * * *
* ** ** * * ** * ** * *** ** * * ** ** * ** * ***** ****** * *
* * * *** ** ** * * *** * * ** * * **

    }


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

    {
* ** * ** * *** ** ** *** * *** * ********* * * * *** **** * * ** s[i]);

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



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



int main ()

{
* ** ** **** * **** s[100];
****** *** * * ** ** * i, pos1=-1, pos2;


*** *** **** * * **** ***** *
** * * * * * ** ** *** * = strlen(s);




* ** ***** * *** * * for when there is no a at the start of the string
* ** *** ****** * ** * *

    {
* ** * ** * * ** ** ** ** *** * ******* * (s[i]== 'a')
** * * ** * * * ** ** * ** * * * * * ** *
** * ***** * * * * *** ** * * *** ** * * ** * * ** ** * ****
* **** ** ** * ** ** * * ** * *** * *
* ** ******* * * ** ** * *** ** ** * * *****
* * * * *** * * ***** * * * **** *** ***
* *** **** ** **** * ** * ** **** * * * ** * *** *** * **** ***
* ** ** ** ** ***** ** ******** **

    }


* * *** **** ** * * **** ** * ** for when there is no a at the end of the string
** * * ***** * ** ** * * * * * *** * *** *

    {
* * ** ** *** ** * ** ** **** * ** **** * **** (s[i]== 'a')
** * * * * * ** **** * **** **** ** *** *
* **** * * *** **** * ** * * ** ** *** * * * ** ** * *** ***
* * *** ** * * ****** ** ** * ** *
* * * * * * * * * ** ***
* * ** * * ** * * ** ** ** ** ** * * * * * *
* ******* ******** ** * ***** * **** * * * *** *** * ******* *
* * *** * ** * ** * ** *** ** *** * ** *** *

    }


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

    {
* * ** * * * *** ** *** ** ** * * * ** **** * * ** * * ******** s[i]);

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



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

int main()

{



    char ch[100];

    int i;


* *** * * ** * **** * * * * ** * *** ** ***** * * * != '\n';i++)
* *** * * * * **** * * * * ** **
**** ** * ** **** * * * *** * * ****** * * **** ** *** * ****** *
********* * * * **** * * * * *** *** * *** * * ** **
* * ** ***** * * * * * * ** *** * ** ** ** * ** * * * * ** *
* ** *** * ** ** **** * ** * ** ** ******* * *
** * * * * ** ** * * ** * * * *** ** * * * ** *** * * * * * ** * * * **
*** * *** * * **** *** * * * *** ***
* ***** ** ** * ** ****** *** *** *** ** * * * * * ** != '\n';i++)
*** ** ** ** * * * * *********** * ** ****
*** * * * *** * * *** *** * ** * * ** * *** *** * * * **
* * ** * ** * * *** *** ** ***** **** * * ******** * ***** ***** ***
* *** ** * ***** ** ** * * * * ** *** * * * * **** * * * * * ** * ** ******* ****** * *** * * *
*** * * * ** * ** * * *** *** * ** * ** ****** *** ** * * *
** **** * ** *** ** * *** * **** **** * *** if(ch[i+1] == 'a' || ch[i-1] == 'a')
**** ** * * ******** * ** * ** *** * **
** * * ***** ** ** * ***** * *** ** *** *** * * * if(ch[i] == 'a' && ch[i+1] == '\n' )

        {



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

        }









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



int main(void){
* ***** * ** * *** * * * ch[100]={0};
** * *** *** * * * * * * i;


*** * * * * * * ** * ** * ** *** ch);


* *** ** * * * i<100; i++){
* * ***** * * * * * * * ** * *** *** *** * * break;
* *** ** ******** *****


*** **** * ***** ***** * i>=0; i--){
*** * * ** *** * *** * * ***** ** ***** ****** ** && ch[i]!=0) break;
* * * * * * *** * * * * *


** * ***** * * * *** End=i;


**** * * ** * * * * ** * i<=End; i++){
* * * * *** ** *** *** ** *** * * * * ** ** continue;
* *** * ** ** ** * * * * *** * ** * break;
*** **** **** * * * **


*** **** * * * * * *** * ; i<=End; i++){
*** * *** ** * * * ** *** ** * * * * * ******* *** ch[i]);
*** ****** *** ** *


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

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



int main(void){
* * *** ***** **** * *** ch[100]={0};
* * *** ** * ** **** ** * i;


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


* * *** ** *** ** *** ** ** * * i<100; i++){
** * *** * * * *** * **** * * * ** ********** break;
** ** *** ** * *
****** * * * *** * i>=0; i--){
* ****** * ***** **** * ** * ****** * ****** ** *** && ch[i]!=0) break;
* * ** ** * ******* *******
** * * * * * ** ** * * ** End=i;
** * * ** *** *** ** ***** i<=End; i++){
* * ** * ** * ** *** * ******* *** **** * * * continue;
**** ** * *** ** * * ** ** * **** * * * ** * break;
** ** ** *** ***** *** ** *
*** * * * *** **** ******* ; i<=End; i++){
* * ** *** ** *** **** * * * * * * * * ******* * ******* * ch[i]);
* * * * *** * **


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

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



int main(void){
**** * * ***** * * ** ***** input, ch[100];
*** * ** * ** *** i;
** * * **** ** ** * ** ***
** **** * ** ** ** ** ** **** ** ** * ** * *
* *** * * * * ** * * ***** ***** * * * * * ** ** * * ** return 0;
*** * * * *** *** **** * *** * * * * ** ** || input=='A') continue;


**** *** **** * ******* ** * ** *** ** * **** *
** **** ** ** * **** *** * * ***** ***** * * * i<100; i++){
* ** * ***** *** *** ** * * **** ** * * * *** *** *** *** ** **
** ** * *** * * * * * * * * * ** * * ** ** * * ***
* * * **** ** * * * ** * * * ** ** * * * ** *** ** ** * *** *** ** ** * ** *** ** * *** ** *
* * * * ** *** *** ** ** * * * ***** * * * **
* * * ** * ****** ** * * *** * * **

    }
*** * * * **** ******* *** i>=0; i--){
** * * * * * * * * ** *** ** *** ** * * **** * * *** && ch[i]!='A') break;

    }


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


*** ** ***** * * * **** * i<=End; i++) printf("%c",ch[i]);


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

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

#include <string.h>

#include <stdlib.h>



int main(){
* * * * ****** *** ** a[100];
** * ** * *** ** * * i=0;
***** ** **** ** ** * * temp;
* ***** ** *** *** *** ** * * **
* ** ***** ******* * * *** ** ** ****** * **** * * len = strlen(a);
* * * * * * ** ** ** ** * ** * == 'a'){
************* * *** *** ** * * * * **** ****
* * *** * ** * * ** **
* ** ** **** * * **
** ** ** ***** *** ** * = 'a'){
* * *** ** * ** == 'a'){
**** ** * **** * **** * * ** * ** * *
** ** * ** *** *** * *


* ** * ** * ****** = i;temp<len+1;temp++){
** **** ** *** * * ** * * ***** *** * ****** ******* * * * * ** *
* ***** ** * *** ** * * * **
*** ********* * * * ** * 0;

}

else{
* * * * * *** *** * * * * = i;temp<len+1;temp++){
* * ***** ** * * * *** * *** ** * ** **** ** * *** * * * *** *
* *** * * * ** * * * *** ***
** * ** *** ** * *
* *** * ** *** ** **** * 0;

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

#include<string.h>



int main(void)

{
* * ** *** ** *** **** * ch[100],ch2[100];
** * ***** ** *** * i,k,p,t=0;
* *** * * *** * ** * ** * * * * ***** **


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

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


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

    }


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


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

    }


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

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



    }





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

Related questions

0 like 0 dislike
23 answers
[Exercise] Essay (Open question) - asked Mar 23, 2017 in C
ID: 23262 - Available when: Unlimited - Due to: Unlimited
| 756 views
0 like 0 dislike
87 answers
[Exercise] Coding (C) - asked Mar 2, 2017 in C
ID: 22313 - Available when: Unlimited - Due to: Unlimited
| 1.6k views
1 like 0 dislike
58 answers
[Exercise] Coding (C) - asked Mar 23, 2017 in C
ID: 23261 - Available when: Unlimited - Due to: Unlimited
| 1.2k views
0 like 0 dislike
50 answers
[Exercise] Coding (C) - asked Mar 16, 2017 in C
ID: 22973 - Available when: Unlimited - Due to: Unlimited
| 1.1k views
12,783 questions
183,443 answers
172,219 comments
4,824 users