0 喜歡 0 不喜歡
2k 瀏覽

Each string will have two strings (string A and string B), each sub-string has 5 characters. 

Write a program with a function compare(string A, string B) for comparison

輸入兩個字串(string A, string B), 每個字串有五個字元

寫一個compare(string A, string B)函數。不能用字串函式庫

If String A == String B returns 0

If string A> string B returns 1

If string A <string B returns -1

Do not use string libraries

Example input:

gamesbegin

Example output: (because g>b => 1)

1

Example input:

iamigiates

Example output: (because m<t => -1)

-1

 Example input:

111qq111qq

Example output:

0

Remember: You may correct the cases, but your code always be revised! 

[練習] Coding (C) - 最新提問 分類:Chapter 13: Strings | 用戶: (5.2k 分)
ID: 40713 - 從幾時開始: 2018-01-04 18:00 - 到幾時結束: 無限制

修改於 用戶: | 2k 瀏覽

53 個回答

0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>

int main(void)
{
    char word[10];
*** ** * * ** ** * * * *** *** ** * **

    int i;
* *** * *** * *** * *** ** * *****
    {
* ******** * * * **** *** * ** * * ** * ** * *** * *** * ***
** ** * * ** * ** * * * * * * * * * * *
*** ** * *** ** ** * * * ** * *** * * * * *** * ***** * ** * ** * * * *****
*** *** ** ** * ****** * ** * * ** * ***** * ** ******** * *** *** 0;
* * * * ** **** ***** * ** * ***** ** **
*** **** ** * * * **** * * * ** * ** * ** if(word[i]<word[i+5])
** **** ***** *** * ******* * ** * * ** * *
** ** * * ** * * * ** * *** * ** * * * * *** *** * ** **** * * * *** *
* * * * ** ******* * *** * ** *** *** ** * *** ** *** * ** *** 0;
* ** **** * **** * ** * * * * *** * *
    }
**** *** ** ***** *** ** **** * ** * ***
*** * ** ** *** * * * * 0;
}
最新回答 用戶: (-140 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int  compare(char A[10] , char B[10])
{
* *** ** * ** * i;
***** * **** **** * ** ** * *** ***** **
* ** ** * **** *** **** **
** ** **** * * ** ** ** * ******* * **** **
* * ** *** ** *** *** * ** * * * ***
** ***** * * *** * * *** **** * * * ** * ** ** *** * ** ** ** * *** 1;
** ** * **** ***** * ******* *** **** * ** ** **** * * * *
**** * * * * * * * ** ** **** *** **

** *** *** * *** * * ** * **** ******* ** *** if(A[i]<B[i])
* *** *** *** * * *** **** ** * **** **
** ** ** *** * ** * ** ** **** * * *** * * * **** * * -1;
** **** **** *** * * **** * * * * **** ***** ** **** *** * * ** * *
* * * * *** ** ** * * ***** ** * * * ***
*** ** * ***** * ****** ** * ** * ** * * * * * 0;

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



}


int main()
{
** * * ** ** ** **** * A[10],B[10];
    int i;
*** ** ** ** ** * *** **** *****
* ** ** * ** * * *
    {
***** ** *** * * * *** ** * * ** * * ** * * * ** *
    }
** *** ** * * * ** * * * ** * * ***
** *** * ** * * ******** * * *** * * **** **
}
最新回答 用戶: (-32 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
int compare(char A[10])
{
** *** **** *** ** * * i;
** **** * * * * ** ** * * *******
* * ** * * ****** ***
* ** * * * ** ** ** * * **** * ** ** **** * * ** return 1;
* * * * ******* ********* * *** **** * *** ** **** * * *** return -1;
* * **** ** * ** *** *
* ***** ** ** ***** 0;
}
int main()
{
* * ** * ** * ** ** A[10];
* * ** **** * ****** * * ** ** * * ** *****
** * * ** * * * * ****** * ***
** * ** ** ***** * 0;
}
最新回答 用戶: (-196 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
* * ** * *

int **** **
{
* ***** * char word[10];
* * ** * * **** ** ***** **
* * * *
* * ** * *** int i;
** ** * * * *** ** *
**** * * {
*** * * * * * * * * ** ** ** *
* * *       {
* * **   * *** ** *** ** * *** * * * ****** * * *
***** ** * * ** ****** ** * ** return 0;
*** * * ** *** * **** }
** *** * ** * * ** * * * else * ** * * * **
** * * * ** * ** {
* * ***** * * **** * ** * ** * ** *** ****
* * * * * * **** * * *   *** * * return 0;
** * ** ** ** * * }
** * * }
*** * * * * *** * ** * **
****** * * * return 0;
}
最新回答 用戶: (-249 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
* * ** *** *
**** * * * * * * * *
***** * ** * *** *
int * ** * *** ** char ***** *
{
** * * * * ** for(int i = 0; i * 5; i++)
** * ** {
* *** *** ** * * * * ** * * * **** ***** **
*** ** *** * * ** * ** *** * return -1;
***** * **** *** * * ** ** ** *** * * ** * * ** ***
*** ** * * * *** ** ***** **** return 1;
* * * ***** }

** * * * return 0;
}
int ** ***
{
* ** ** char * **

***** * * *** * char * * **

* ** * * ** i = 0; i * * 5; i++)
* * ** *** ** {
* *** ** ** ******* ** * * * ** ** **
*** * * ** ** }

** * *** for(int i = 0; i 5; i++)
** * {
* * * * *** *** * * ** * ******* * ****** ** * * **
* ** *** * * }

* * * * ** * * **** ** * * **** *** * * ****
}
最新回答 用戶: (-285 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
** ** * **** * ***
* * ***** ** ***
** ** ***** * *
int **
{
**** * * * * char ** ***

* ** * **** ** char * ** **

******* * * * * i = 0; i * * 5; i++)
***** * * {
* * *** *** * ***** ** * * * *** * ** *** ****** ** * ***
* ** * * }

* * ** * * * * for(int i = 0; i * 5; i++)
* *** ** *** ** * {
** ** * ** *** * ****** * * *** **** **
** ** ** * }

** *** *** * * ***** * * ****** ** * **
}
int * * ** * * *** char *** *
{
* *** * ** * for(int i = 0; i *** 5; i++)
* *** *** * {
** * * * * * * * **** ** * *** * **
** * ** * * ** *** ** * * * ** * return -1;
* ** * ** ** * * * * * *** * * **
* * * * * *** ** ***** * * ** * return 1;
*** }

* * * * return 0;
}
最新回答 用戶: (-285 分)
修改於 用戶:
0 0
prog.c: In function 'main':
prog.c:20:15: warning: implicit declaration of function 'compare' [-Wimplicit-function-declaration]
  printf("%d", compare(string_A, string_B));
               ^~~~~~~
0 0
prog.c: In function 'main':
prog.c:20:15: warning: implicit declaration of function 'compare' [-Wimplicit-function-declaration]
  printf("%d", compare(string_A, string_B));
               ^~~~~~~
0 0
prog.c: In function 'main':
prog.c:20:15: warning: implicit declaration of function 'compare' [-Wimplicit-function-declaration]
  printf("%d", compare(string_A, string_B));
               ^~~~~~~
0 喜歡 0 不喜歡
內容已隱藏
*** ******** ** ***
* * ** * * **** **

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

*** ** **** * char **

* ** ** for(int i = 0; i *** 5; i++)
* * *** {
* ***** ** * ** * * * *** * * * * **** ** ** ** * * * * *
*** ****** }

**** **** * *** i = 0; i * 5; i++)
* * * {
* * * ** * * * **** * * ** * *** *** ***** ***
*** ** * }

* * ** *** ****** ** * ** ** * *
}
int * * ***** ** char ** **
{
*** ** *** * * ** i = 0; i ** 5; i++)
* * * ** *** {
** * * * * * ** * * * * *** * *
** * * *** ** * * * *** ** *** *** return -1;
* * *** * * ** *** *** *** ** ** * * * * * * *
* * * * * *** *** * * *** return 1;
** * * ***** }

*** * * * return 0;
}
最新回答 用戶: (-285 分)
0 0
prog.c: In function 'main':
prog.c:20:15: warning: implicit declaration of function 'compare' [-Wimplicit-function-declaration]
  printf("%d", compare(string_A, string_B));
               ^~~~~~~
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
#include<stdlib.h>

int main()
{
    char a1,a2,a3,a4,a5,b1,b2,b3,b4,b5;
* * * *** ** * * *** * * * ** *** * * ****** ****** ***** ** ***** * *** * * ** * *** ** * * * **
    if(a1>b1)
* ***** * ** ** ** * * ** * * *** ** * ** ***
* * * ** **** * ** ** ***** *** **** if(a1<b1)
* * *** ** * **** * ******* * * * ***** * * **** ****
* * ** ** *** ** *** * ***** ** if(a2>b2)
** * ** **** *** **** ** ** * *** * ***** ****
** ****** ******** * ** * **** * ** * ** if(a2<b2)
* **** *** *** * * ** **** ** * * *** *** * ** * * * * ** ** * *
** * ****** **** * * * ******* *** ** if(a3>b3)
* * * * ** ** ** * * ** **** *** * * **** ** * * * ** ** **
* * * ** * ** * * * *** ** if(a3<b3)
* * * ****** ** * *** * * * ** * * *** *** ** *
**** *** *** **** * * ** * if(a4>b4)
** * * *** * ** ** * * ** * *** * ** * * ** ******
**** ** * ** * * * * * ** * if(a4<b4)
* * * * ** ** * ** ** * * ** * ** ** * *** * * ***** * ***** *** **
** *** ** * ** ** * ** ** if(a5>b5)
*** * *** *** *** * *** *** ***** * ** * ** ***** * *
* ** * ** * *** * * * ** ** if(a5<b5)
** * ** * *** * *** * *** * *** * *** ** ** * * * *
*** ** ** **** * * * * *** ***** *
* * ** * ** * * * * * * * * * * * * * ** * * * * ** * **


    return 0;
}
最新回答 用戶: (-16 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include <stdlib.h>

int main()
{
* ** ** ** * ** * * * **** * word[10];
* **** *** ********* ** * ***** * * word);
    int i;
* * ** * ** * * = 0; i<=4; ++i)
    {
* * ** * ** ** * ** * ** * * ** ** * ** ** *** * *
* * * * ****** *** ** ** ** **** * *** ***
** ** ** **** ** * *** ** * **** * ** ** * **** * * * * ** ** ** **** * * *** ****
**** ** ******** ** *** ** ** ** **** * *** * * ** * * * * * *** * ** 0;
* * ** * *** *** ** **** * ** * ** * * **
* * * * ** ** ** ***** **** *** **** * ******** * * if(word[i]>word[i+5])
** ** *** ** **** * ** * ** ** ** * * * **
* ***** ** ** ***** ** * ** * ** * * *** *** * * *** ** *** * ** *
* *** * * * **** * * ** * ** ** ** * * ** * ** * * ** ***** *** 0;
* ** **** * ***** * ****** * ** ** * *** * * **
    }
** * ** *** * * *** ** *** *
* * * * * * * * * 0;
}
最新回答 用戶: (-284 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include <stdlib.h>

int main()
{
* *** ***** * * *** ** word[10];
* ** * ** * * ***** * * * * *** *** * * word);
    int i;
* * **** ****** * ** ** * = 0; i<=4; ++i)
    {
* *** *** * * *** ** * ** * ** ** *************** ** * *
** ** *** **** ** *** ******* * * ** *
** * ** * *** * * *** **** ** * ** *** * ** ** * * * * * ****** ** ** * ** * * * *
* * *** ** * * ** ** ** ** * *** * ******* ******* * * * * **** ** ** 0;
* **** * ** ** * * * * ** *** ** * * * * ** *
**** * ** * *** *** * ****** ** * * * * **** if(word[i]>word[i+5])
* * ***** * * ** * * ** * ** * * ** ** * **
* * * * ** * * **** * * * **** ** ** ***** * *** ** ** ** * * * * * * * ** ** * * **
** ** * * *** *** * ** * * * * * **** ** *** ** ** ** ****** 0;
***** * * ** ** ** **** ** * * **
    }
*** ** * * * * * * ** * *
*** * * ***** *** * * * 0;
}
最新回答 用戶: (-108 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.254.132
©2016-2024

相關問題

0 喜歡 0 不喜歡
53 回答
[練習] Coding (C) - 最新提問 1月 4, 2018 分類:Chapter 13: Strings | 用戶: semicolon (5.2k 分)
ID: 40715 - 從幾時開始: 2018-01-04 18:00 - 到幾時結束: 無限制
| 2.3k 瀏覽
0 喜歡 0 不喜歡
27 回答
[練習] Coding (C) - 最新提問 1月 11, 2018 分類:Chapter 13: Strings | 用戶: thopd (12.1k 分)
ID: 41439 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 1.9k 瀏覽
0 喜歡 0 不喜歡
44 回答
[練習] Coding (C) - 最新提問 1月 4, 2018 分類:Chapter 13: Strings | 用戶: semicolon (5.2k 分)
ID: 40714 - 從幾時開始: 2018-01-04 18:00 - 到幾時結束: 無限制
| 1.8k 瀏覽
12,783 問題
183,443 回答
172,219 留言
4,824 用戶