0 like 0 dislike
1.9k views

       在某座古老的遺跡地底,有著三個寶箱,分別為A,B,C,找出正確的那一個。三個寶箱上各有一段文字(文字內容只有大小寫英文字母跟數字),找到正確寶箱的方法是,計算該寶箱的文字中出現過該寶箱的代碼之次數(即A寶箱上的文字出現「A」的次數,以此類推),找到出現次數不一樣的那個,此即正確的寶箱。

例如:A寶箱上文字出現的A的次數為20,B寶箱上文字出現的B的次數為20,C寶箱上文字出現的C的次數為15,則C寶箱為正確的藏寶箱(大小寫視為相同)。

請設計一程式,能讓使用者到正確的寶箱,使用者會輸入三段字串(以空格格開,且分別不會超過300個字元),分別為A,B,C寶箱上的文字,請輸出正確的寶箱代碼。

提示,若該寶箱文字中未出現該寶箱之代碼,或是出現連續3個4(即,444),則該寶箱就非為正確寶箱。若無正確寶箱即輸出0。

sample input 1

ApencilISawritingi24mpLeMentor48artMEdiumCO24NStructedo8FANarrOw solidpigment35coreinsideaprotectivecasingwhic25hpreventstheCOrefrombei268ngBROkeno stcommonTYPOE34cilc7asinVISsofthinwFK3BOLCodusua660lyinsectionbutsometimes 

sample output 1

B

sample input 2

ApencilISawritingi24mpLeMentor48artMEdiumCO24NStructedo8FANarrOw solidpigment35coreinsideaprotecti444vecasing stcommonTYPOE34cilc7asinVISsofthinwFK3BOLCodusua660lyinsectionbutsometimes 

sample output 2

0

[Normal] Coding (C) - asked in 2016-1 程式設計(一)AC
ID: 19390 - Available when: Unlimited - Due to: Unlimited

reshown by | 1.9k views

13 Answers

0 like 0 dislike
Hidden content!
* * ** ** ** *
**** *** * *** * **
*** * *** *
* * *** **** * **



int main(){
* ***** *** ** ** *** a[301]={0}, b[301]={0}, c[301]={0}, s[4]={4,4,4, '\0'};
* *** * * *** * * * *f, *o, *p;
* **** ** ** ***** *** i, j ,k, sa = 0, sb = 0, sc = 0;
** *** * * * ** ** %s %s", a, b, c);


* ***** ** ** ** * ** ** * = 0; i < 301; i++){
* * ** * ** ***** * ** ** * * ** ** ** *
* ** *** ** * *** * *** *** ***** * * * * * * = tolower(a[i]);
** * * * * * ** * ** * ** ** * *** ***
** ** ** ***** ****** ** **** **** ** ** * *** * *** * * * = tolower(b[i]);
** * ** * * * * ** * **** * * * * * * ***** ******
** * ** *** * **** ** **** *** ***** * * * *** = tolower(c[i]);
* ** * ** * ***


** * *** **** * * = 0; j < 301; j++){
*** ** * * * * * ** ** * ***** == 'a')
*** ********* * **** ** * * ** ** * * ** * *** ****
** ** *** ** * *** ** * * * * * * * == 'b')
* * * * * * ** * ** * ****** ** * * * *** * * **
** * * * * ** ** ** *** * ***** * **** *** == 'c')
* *** * * **** * ** *** ** * ** *** * ** *
* * * * * ** *
*** *** * ** ** ** = strstr(a, s);
**** * ***** * * = strstr(b, s);
**** * ** * **** = strstr(c, s);






** ********* * * * ** == sc && f == NULL)
*** ** * * **** *** ** **** ** *** ** * ***
* ** * ****** * **** if(sb == sc && o == NULL)
* * ** * * **** * * * ** * * * * *
* *** * ** * ** if(sa == sb && p == NULL)
* *** * **** *** * * ***** * * * * ** * ***
** * * ** * * * *
* * ** * *** * ** *** *** * *** * * * *



return 0;

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



int main(){
* * * ***** * * *** *** a[301]={0}, b[301]={0}, c[301]={0}, s[4]={4,4,4, '\0'};
* * * * * * *f, *o, *p;
* * * * * *** *** * * i, j ,k, sa = 0, sb = 0, sc = 0;
* *** * ***** * * * %s %s", a, b, c);


* * ** * * *** * ** * ** = 0; i < 301; i++){
* * **** * ** * * * * ***** *** **
* * ** *** * * * * ** *** ** **** * ** ********* = tolower(a[i]);
* ** *** ** * * * **** * *** *** ** * ** * ** *
* ** *** * ** * * * * ** * *** ***** * ** = tolower(b[i]);
* ** * * * * * * * * **** ** * ** * * ***
* ** ***** **** * *** *** *** * * * *** ***** = tolower(c[i]);
* * * ** * ** * **


* * *** ** * *** = 0; j < 301; j++){
*** * * * * * *** **** *** * * ** == 'a')
*** * **** *** * ** * * ** *** **** ** *****
* * * ** *** * * * * ****** == 'b')
** * * * ** *** * * * ** ** * ** * * * * * ** ***
** * ** ***** * **** ** *** * ** ** * ** ** == 'c')
* ** * * * * ** * **** * ** *** * ******* * *******
** * * ***** *
*** * * ** ** ****** * = strstr(a, s);
* ** ** *** * * = strstr(b, s);
******** * * *** * = strstr(c, s);






**** * *** * ** == sc && f != NULL)
** * ** ** ** * **** ** *** * * **** **** * * **
*** * *** **** if(sb == sc && o != NULL)
* * ** ** * ******* ** *** * * * ** *** ***
**** *** *** * * * if(sa == sb && p != NULL)
** * ** ** * * ** ** *** * * * ** **
***** * * * *** *
* ********** ** * *** *** ***** ******* * ** *



return 0;

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

#include<stdlib.h>

#include<string.h>

#include<ctype.h>



int main ()

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

    char s[10]="444";

    int *** * ** ** ** * * **** * **** *** * *
** ** ** ** ** ** * * * * * * * ****
* * *** ****** * ** * * * ***** * * * **
*** * * ****** * * * * ******** ** ** **
**** ***** **** * * * = strlen(box_a);
** * * *** * ** * = strlen(box_b);
* **** * ******* ** * ** * * = strlen(box_c);   

    for (i=0;i<length_a;i++){
** ******* **** * ** *** *** *** * ** = box_a[i];

** * * * *** ** ** * * * ** ** * **** ****** **** = tolower(a1);

* ** ** **** * **** ** ** * * * * * *** ** * * ** ** *** = a1;

    }

    for (j=0;j<length_b;j++){
** ** * * * * ** * * ** *** * * * * ** * = box_b[j];

* * * ****** * * * ** **** ** * ** = tolower(b1);

* * * * ** * *** ** ** ** **** * * **** * = b1;

    }

    for (k=0;k<length_c;k++){
**** * **** * * * ****** * ** * * * ** ** * = box_c[k];

* * * ** * *** ** ***** * * ****** * = tolower(c1);

*** ** *** * ** *** *** ** * * **** * * * ** ** * = c1;

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

    
***** ******* * * * *** != NULL)
**** * * ** * *** * * **** * * ** ** * * * *** *
* *** * * * * * * * if(ptr2 != NULL)
* ** **** *** * **** ** * ***** * ** *** *** * * * * * *** * *

    else if(ptr3 != NULL)
* * * * ** * * ** * *** ***** ** * * ** ** * * ** * * * **
**** * ** * ** ** ***

    {
* * * ** **** * * ** * * *** *** * ****** *** * *    
*** ** * * **** ** *** ****** **** * * * *** ***** * ** ******* == a)
** * * * *** * ** *** *** * *** * * * *** *** * ** ** ** * * ******** * * ** *
* * * * *** *** ** ** ******* **
* ** * *** * ** * * **** * * ** ** ** **** * *
** *** * ** **** * *** ** *** *** **** * * * * ** * ** ******** ******* * == b)
* *** * *** *** ** ** * ** * * * * *** * **** *** ******* ***** * *** * ** * ***** ** *
* * * * * * * ****** ** * ******* *** * * ** **   
* * * * * * * * ** ** ** * **** *** * ** * * *
** ** ** ** **** * * ** *** *** ***** * *** ******* * * * ** **** ** **** *** == c)
* ** *** ** * *** * ***** * * * ** ** *** * ** * * ** * * ****** * * * *** * * * ** *
*** ** ** ********** ** ** ** * ** * ****** ***   
*** ** * * **** * ** * * **** * ** **** **** * * (count_a == 0)
* * *** * ** * ** ** * ** * * ** * * * ** ** **** ** * * *** ** ***** ****** * ***
* ** ****** ** ** * * * ***** ** ** if (count_b == 0)
* ** * ** ** * * **** ** **** * * ** **** ** **** * * ** ** * ** * ** **
** * * *** * * ** * *** * ** *** ** ** * if (count_c == 0)
** *********** * * **** ** * * ** ** * * ** ** *** * * * ***** * ** *** ** *
* ** * ** * * * ** *** ** * *** *** ** * **
*** * **** ** * * ****** **** * *** **** *** * * * * * * **** == count_b)
* * * * *** **** * * *** ** * * *** **** * ** * **** * * **** * **** *** *** ** * * * **
* * ** * * * * ***** * * * *** ** ** ** * * *** ** * ** * ****** ** if(count_a == count_c)
* * * ***** * * *** * * * *** * *** ** * * ***** ****** ** * * * * * *** ** ** * ** ** ***** **
** * ** * * ** *** * * * ** * * ** * * * ** * ** * * * if(count_b == count_c)
* * *** **** * * ** ** ** *** ** * * * *** * ****** * * * ** * ** ** * ** *
* *** ** ** * *** * ** * ** ** * * ** * *** ** * ** * ** * ** * * printf("0");
* *** * * ** ** *** ** * *** ** ** ** *** * *** *

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

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

Related questions

0 like 0 dislike
24 answers
asked Dec 7, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points) | 2.4k views
0 like 0 dislike
9 answers
asked Dec 31, 2016 in 2016-1 程式設計(一)AC by Gulang (-122 points) | 1.3k views
0 like 0 dislike
3 answers
[Normal] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC
ID: 20997 - Available when: Unlimited - Due to: Unlimited
| 707 views
0 like 0 dislike
7 answers
[Normal] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by 林佳慧 (-85 points)
ID: 20976 - Available when: Unlimited - Due to: Unlimited
| 929 views
12,783 questions
183,442 answers
172,219 comments
4,824 users