3 like 0 dislike
4.1k views
字串比大小

字串也是可以比大小的,通常都是透過ASCII碼來判斷字串的大小

請寫一個程式依照下列的規則判斷字串的大小

1. 不分大小寫 "a" 跟 "A" 一樣大

2. "a" > "b"

3. "a" > "aa"

輸入說明:

會輸入兩個字串,臉字串間用空白隔開

輸出說明:

請依照範例輸出兩字串的大小關係

輸入範例1:

book cook

輸出範例1:

book > cook

輸入範例2:

being be

being < be

輸入範例3:

include INclUdE

輸出範例3:

include == INclUdE
[Exercise] Coding (C) - asked in 2017-1 程式設計(一)AD by (18k points)
ID: 33758 - Available when: Unlimited - Due to: Unlimited
| 4.1k views

20 Answers

0 like 0 dislike
Hidden content!
#include * * ***** ** ** *
#include * * * * ** * *
int main()
{
* ***** * **** char * *
*** * * * char *** **
* *** *   int * * *
** ****   **** *** *** ***** * *** * *
*   ** ***** * *** * *****
* *   for( j=0 ; ** *** * )
* ** ***   {
*****   ** * * *** * * ** ** * * * * * ** ****
** *   ** * ** * * * * = str1[j] + 32;
** * ** ** * ******
* * * * * **** * * ***** j=0 ; * * * ** * )
* *   {
**   ** *** *** ***** * **** ** * * ** * * * * * *
*** *   * ** *** * * ** * = str2[j] + 32;
** * **** * * ** ** *
***** *** * * **** ***
* ** *   ** **** **
*** * ****** * ** * * = *** ** *
* * * *  
*** ******* * ** ** *** *** ** * ** >0)
* *** * ** * * * ** ***** * < ** * ***** * **
** * * ***** * * * * * * *
* *** * * * **** * * ** ** <0)
* **** * *** * * ****** * > ** * * ** * *
* *** **** **** * *
** *** *** *** ** * ** *** 0;
** *
answered by (209 points)
0 0
prog.c: In function 'main':
prog.c:8:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
  scanf("%s",&str1);
          ^
prog.c:9:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
  scanf("%s",&str2);
          ^
0 like 0 dislike
Hidden content!
#include ** * ** ** ** *
#include ** * ** **
int main()
{
* * * * char **** * *
** * * * char ****
***   int *** *
*** *** *   * **** * ***** * * ***
* **   * ** * * * ******* * * *
** *   for( j=0 ; *** * * * )
* **   {
*   *** ** ***** * * ** ** * **** * * * ** *** ** ** *
*** **   ** * ** * * * = str1[j] + 32;
* *** ** ** * ** *
* *** ** ***** * *** * j=0 ; *** **** )
* *   {
* *   ** * * ****** * * *** * * * *** * **** **** ****
* * *   * * * * ****** *** *** = str2[j] + 32;
**** * * ** **** ** *
* ******** **** * * *
*****   * * ** * * * *
* ** *** * * * * = ** ** * ** * * *
* * *  
* * ** * ** *** * * *** ** * * >0)
* * * * * ** * *** *** < * ** * ** **
****** * ** ** * * ****
* ** ** * ******* ** ** * * <0)
* * * **** *** * * ** ** * *** * > * * * ***
** * * ** *** *** * *
****** * *** * ** ** 0;
* **
answered by (209 points)
0 0
prog.c: In function 'main':
prog.c:8:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
  scanf("%s",&str1);
          ^
prog.c:9:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
  scanf("%s",&str2);
          ^
0 like 0 dislike
Hidden content!
#include **** ** *
#include * * ** **
int main()
{

int ret,h;
char **** * *

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

* * * *
* ***** *** ** * * *** ** * *** ****** * ** * ** * * ** * *
else if(ret==0 )
* * * ** * * ** ** * *** *** * * ****** ***
else
** ** * * * *** ** ** * ** * ***** * * ** **
return 0;


}
answered by (174 points)
0 0
prog.c: In function 'main':
prog.c:9:9: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
 scanf("%s %s",&str1,&str2);
         ^
prog.c:9:12: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'char (*)[1000]' [-Wformat=]
 scanf("%s %s",&str1,&str2);
            ^
prog.c:10:5: warning: implicit declaration of function 'stricmp' [-Wimplicit-function-declaration]
 ret=stricmp(str1,str2);
     ^~~~~~~
/tmp/ccBKmsbO.o: In function `main':
prog.c:(.text+0x56): undefined reference to `stricmp'
collect2: error: ld returned 1 exit status
0 like 0 dislike
Hidden content!
#include * ** * * * *
#include ** ** *
int main()
{

int ret;
char * * * *** ** *

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

* * ** *
* **** ***** ** ** ***** ** * * * *** **** ****
else if(ret==0)
* * ***** * ** ** * * * **** ** **** * * **
else
** * * * *** * ** * ** *** ** ** ** ** * *** ****
return 0;


}
answered by (174 points)
0 0
prog.c: In function 'main':
prog.c:9:8: warning: zero-length gnu_printf format string [-Wformat-zero-length]
 printf("");
        ^~
prog.c:10:1: warning: 'gets' is deprecated [-Wdeprecated-declarations]
 gets(str1);
 ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:11:8: warning: zero-length gnu_printf format string [-Wformat-zero-length]
 printf("");
        ^~
prog.c:12:1: warning: 'gets' is deprecated [-Wdeprecated-declarations]
 gets(str2);
 ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:13:5: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
 ret=strcmp(str1,str2);
     ^~~~~~
/tmp/cc7PFS17.o: In function `main':
prog.c:(.text+0x25): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
*** ******** ****** ****
* * *** * **
int main(void)
{
** * * **   int a;
* ***   char * *** * * *
* * *   ** *
* ** * * ** * ******
**** ** * **
** ** ** *** * ** * *** *
* * ****** * *** *
* * * ** *** * *** ****** *****
* *** * * * * * **** ****** * **
* * * * return 0;
**** **** *
}
answered by (160 points)
0 0
prog.c: In function 'main':
prog.c:7:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(str1);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:8:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(str2);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:10:4: warning: implicit declaration of function 'strcmpi' [-Wimplicit-function-declaration]
  a=strcmpi(str1,str2);
    ^~~~~~~
prog.c:13:2: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
  system("pause");
  ^~~~~~
/tmp/cclIJ8jO.o: In function `main':
prog.c:(.text+0x25): warning: the `gets' function is dangerous and should not be used.
prog.c:(.text+0x52): undefined reference to `strcmpi'
collect2: error: ld returned 1 exit status
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
    int i,k;
** ** ***** * * * ***** ch1[999],ch2[999],ch11[999],ch22[999];
    
**** **** * * * ** ** * * ** *** * **
** * * ** *** ** * * * * *** ***
    
* * ** *** * ****** *** * **
    {
* ** * *** *** * * * * **** ** * *** * ** * *** * **
* ** * ***** * * ***** *** * *** * ** * ** ********* * ** *
** * * * ** ** * ****** *** ** ** **
* ** ** * * * ** ***** * * ** ***** **** * * ** ** ** ** *** ***** * ***** *
* * * ** * ****** * * * ** **** *** *** * **** ** * * ** ** *
***** * ** ******* * * * * *** ******* * *
* ** * ******** *** *** **** * ** **** * *
    {
** * ** **** * ** *** * ** **** * ** * * * ******* * * ** *** **
* ****** * * * * * * * ** ******* ** * ** * * * * *** * * **
* **** * *** **** ** * * ** * *** * ***
** * ****** * ** * ** ** * * ** * * * ** * * * ** **** * * ** ** *
** * ** * * * ** * ** * * *** ** **** * ** * ** * * ** **
***** * ** * ** ** ** * *** * ** * ** *** *** ***** **
* * * *** * * * * ** * * * * *
** ******* ** * * * * **** **** ** ******** * * ***** *
***** ** * ** * *** * * ** ***
    
* * * ** ** ****** **
* * ** * *** * * * * * ***** < %s",ch1,ch2);}
* ** ** * ** ** **** *
* * * * * * ** * ** ** > %s",ch1,ch2);}
** ** ** ** **** * * **
* ******** * **** * ** * * *** ** ** == %s",ch1,ch2);}
    
**** ***** *** *** ** *** ***** ***
    
}
* *** * **** ** * * * * * ***** ** * * ** ***
answered by (192 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
    int i,k;
** ** * * * *** * ** ** ch1[999],ch2[999],ch11[999],ch22[999];
    
*** * *** * * ** * * * *** * **
***** * ** ** ** * * * ** ** ** * ** *** **
    
* **** **** * * *** * * * * * *
    {
* * * *** * * * ****** *** * * ** * ** * ** * *** *** *
* * ** ** * ** ** * *** *** ** * * *** * ** * **** ** ** *
* *** *** * * ** * ***** * ** **
* ** ******* *** ** **** ** *** ** * * *** ** *** * * *** * ** ** ***** * * *
********* * ** * ****** *** * * * ** ** * ** ** **** * *** * ** * * * * ** *
* **** * * **** * *** **** * * * *** * ***
* * ** ** ** *** * *** *** ****
    {
*** ** * *** *** ** ** * **** ** * ** * * *** * * * * * * ** *
* *** ****** * * *** ****** ** * **** ** **** ** ** * **
*** * * * * ** * ** ** ** ** *
* ** ***** * * * * * ***** ** ** ***** *** * * **** **** ** * * ****
* ***** * ** *** ** *** *** * **** *** * ** ***** * ***** ** * * * ** **
** * * * * * * * ** * * ** ****** * *** ** * *
* * *** ** ***** * ** ** *** * *
* * **** * *** * ** * * *** ** * * * * ** * * * **** ** *
***** * ** * ** * * **** * * * *
    
***** *** *** * ** * * * ***
** ** * ** * *** * * * **** * *** < %s",ch1,ch2);}
* ** ** * ** ** * **
* * * ***** * * ** * * > %s",ch1,ch2);}
* *** ** *** * * * *
*** ** * **** ** * * ** **** == %s",ch1,ch2);}
    
** * ** ********* * * * ** ** * ** *
    
}
* *** * ***** * * * **** ** ** *** **
answered by (192 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
    int i,k;
*** * *** * * * * * ch1[999],ch2[999],ch11[999],ch22[999];
    
* *** * ** **** ** ****** * ****
* ****** * ****** ** ** * ** * ******
    
*** * * ** *** *** * ****** ****** * ***
    {
* * *** * ********** * * * * ** * **** * * ** * * *** *** **
* *** ***** * ****** * * * * ** * ** ** * * * ** * * * **
** *** ** * ** ******* * * **** *** *
* * *** *** ** ***** *** ** ** ** ** *** * * *** **** * * *** *** **
** * ** * **** * * * ***** * * *** ** ** ** * * *** ** *** * *
* **** *** * * * * *** ** * * * ** * * ** *
* *** * * * **** ** * * * * * * *
    {
** ***** * * * * * ** * ** * ** * *** * * ***** * * ****** * *** *
** * * ** *** * * ********** ** ** * * * ** ** ** *** * ** **
*** ** *** *** * *** * *** * *
** ** *** * * ** ******** ** ** ******* *** * *** * ********* *** * ****
* * * * * * * ** ** * * ** * * * ** * **** ** * ***** * ***** * ******* * *
* * ** ** ** ** * ** **** * * ** ** * * ***
** * ***** * * ** *** *** *** * **
* ** ** *** * * * * ** * *** ** ** * *** * * ** *
*** * ** ** * * * * ** * *
    
** **** * ** * * ** * ***** **
* ** * * * * * ** *** ***** < %s",ch1,ch2);}
**** *** ** *** * ** **
* * ** ** * * * ** ** * * * * > %s",ch1,ch2);}
* ** * ** * *** ** *****
** * ** *** ** *** * *** = %s",ch1,ch2);}
    
***** ** * * ** * * * **** * * * * * *** *
    
}
*** * ** * * *** ** *** * ** * **** * ** *** * * *
answered by (192 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
    int i,k;
    char ch1[999],ch2[999],ch11[999],ch22[999];
    
*** * * * * **** **** *** * *** **** ** *
* * *** * ** ** ** * **** * ** *** * *
    
* * * * * **** ** *** * ** ** * ***
    {
* * *** * * * ** ** *** *** *** ****** ****** * * * *** * * ** *
**** ***** **** * ** ** ** **** * * **** * **** * * **** * * * ***
* * * * *** **** * *** * ** *** ** ** ****
*** * * ** * * * ***** * ** ** ******* * * **** ** ** **** ***** * * *** * * ** **
** ** * * ** ** *** ** * ** * * * ** * * * ** ** ** ** * * ************
* * * ** * * *** ** * * ** ** *** **** ** * *
* * **** * ** ** ****** *** **
    {
** *** * * ** *** **** * *** * ** *** * ** * * *** ** * ** ****
** * ***** **** ** ** * * * *** **** * ******** * *** ** *
**** * *** * *** ** * * * * ** * * *** *
* * ** * * **** * ** **** * * *** ****** * * * *** *** * * ** ** ** * **
** * * *** ******** ** **** ** * * * **** ** *** * ** * ** ******* * **
* ***** ** * **** * * ***** ** *** *** ** * **
* *** **** *** ** * * ** * ********
**** * * * * **** **** * * *** ********* * ** ***
* ******* ** * * ** *** ** *
    
** * *** **** * * * ** *** * *
* * *** * ** *** *** * ** ** * ***** *** *
** * ** * * * ** * *** *
* ** ***** * ** * ***** ** ** * * * * ** * *
    if(k==0)
****** * * * * ** * **** ** ** ** *** * * **
    
**** *** * * * * ** * **** *** * *
   
}
** ** * * * * * *** ** * ** ** ** ** * ** ** * ** **
answered by (192 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>

int main()
{
    int i,k;
    char ch1[999],ch2[999],ch11[999],ch22[999];
    
* * * ******* *** * ** * * **
** * ** ***** **** * ** * * **** * * * *
    
** ** * ** *** ** * ** ** * **
    {
** ***** ** ** * * * * * ** **** ** * * ** ** ** *** * * * *** *
*** * * **** ** * *** ** * * ** * * * ** ***** * * *** *
* * * * * **** * ** * ** ** **** *
* * ** * ***** ** ** * ** * * * ******* * * ** **** * ****** ***** *
*** * ** * **** *** ****** * **** * ** * *** * *** *** **** * * ** *
* *** * **** * * ** *** ** ** ****
** ** * * * * ** * **** **
    {
* *** * * ** * ***** ** ** * *** *** * * * * * * * * * * **** *
* ** ** * **** ** ** **** ** * * ** * ** * * *** * ****** ** * **
* * ** * * ** * * * * * ** **
** *** * * * * ** * * **** *** ******* * *** ** * **** ** ** * * **
*** ** * ** ** * * * ** * * ******* * **** ** ** *** ** **
*** * *** ** *** * ** * ** * *** *** * *
* *** *** * * ****** * ** ** * ** *
**** * * * ** **** * * * * * * * ** ** * **** * * * ** ** * * *
* * ***** * ** * ** *** **
    
** *** * ** ***** ** * *
* * ** ** *** * ***** * * *** ** *** * ***
* * ** ** * *** * * ***
* ****** ***** ** ** * **** * ** * **** ** **** ** *
    if(k==0)
* * * * * * * *** ** * ********* ** ****
    
** * * * * **** **** ***** ** * * * **** *
    
}
** * ***** *** ********* ** * * * * ** ******
answered by (192 points)
0 0
prog.c: In function 'main':
prog.c:29:7: warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
     k=strcmp(ch11,ch22);
       ^~~~~~
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.7.18
©2016-2025

Related questions

2 like 0 dislike
24 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33762 - Available when: Unlimited - Due to: Unlimited
| 4.5k views
3 like 0 dislike
22 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33757 - Available when: Unlimited - Due to: Unlimited
| 5.5k views
3 like 0 dislike
6 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34979 - Available when: Unlimited - Due to: Unlimited
| 1.6k views
3 like 0 dislike
9 answers
[Exercise] True/False - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 33763 - Available when: 2017-11-16 14:00 - Due to: 2017-11-16 14:30
| 903 views
3 like 0 dislike
5 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34978 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users