0 like 0 dislike
7.6k views
蝸牛爬牆問題

有一隻蝸牛,爬在一個高度為h公尺的牆上面,白天往上爬n公尺,晚上下降m公尺,目前蝸牛位於牆上i公尺的地方,蝸牛從白天開始爬,請問幾天後蝸牛會爬到牆頂。

 

請寫一個程式,輸入h,n,m,i四個變數,計算出蝸牛幾天後會爬到牆頂。

如果蝸牛不可能爬到牆頂,請輸出 this is impossible!。

 

輸入說明

依序輸入四個正整數代表h,n,m,i。

 

輸出說明

輸出一個數代表蝸牛幾天會爬到牆頂。

 

範例輸入1

50 5 2 3

 

範例輸出1

15

範例輸入2

100 10 15 0

範例輸出2

this is impossible!
[Exercise] Coding (C) - asked in 2016-1 程式設計(一)AC by (18k points)
ID: 20993 - Available when: Unlimited - Due to: Unlimited

reshown by | 7.6k views

144 Answers

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

#include <stdlib.h>



int main()

{

    int h,n,m,i,d;


** ******* **** ** *** ** *** ** *** %d %d * **** * * * * *** *


* * * * * ** * * ** ***
* ** *** * * * ** ** *** ** ** * * * *** ** ** * is impossible!");

    else

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

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





    return 0;

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

#include<stdlib.h>

int main1()

{
* * ***** * ** * h;
* ** * ** ***** * ***** n;
* * ** ** ****** *** m;
**** ** * ** * *** * * i;
** ** * *** * * * *** * day;
* * * ** * ** ***** ans;
*** * * ** * swn;

scanf("%d %d %d * * ** * ***** * * * **



if(n<=m)
* * * * ** *** * * * *** * *** is impossible!");


****** * * * * *

    {
* * *** * *** * * *** * * ** * * * * *** * *** *
* * * **** *** * ** *** * ***** * * * *** * **
* ***** ** * * ** * **** *** ** *** ** * * **** *** * ****
*** * ** * ** ** * * ** * ** *** ****
** ** * * * * **** * **** ***** ***** * * ** **
* * * ** * ** * * ** * *** ** ** ** * ** **
** * ** * ** ** * **** * ***** *** ** if(((n-m)*(day-1)+i)<h-m)
*** ** * ** * * ** * ** * * ** ** *** *
* * * ** * ** ** ******* * * *** * **** * **** ** * * *
* ** ** *** **** ** *** ** ** **** ** * * ** *****
* * * ** ** * ** *** ** ** * * *** * * * *

    }

return 0;

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

#include <stdlib.h>



int main()

{

    int h,n,m,i,d;


** ** * ** * **** ** * * *** * * %d %d ** * * * * * * * * * * **** *


* ** *** *** *** * ** * *
*** * *** * ** * * * ***** * ** * *** * *** is impossible!");

    else

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

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





    return 0;

}
answered by (-186 points)
0 like 0 dislike
Hidden content!
#include * ** *

#include ******** * ** *


** *** main()



{

int * ******
* * ** ** * *** * ***** *
**** * * **** * ** * *
** * * ** * ** * **** ** ** *
* ** *** * ******* ** *


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

else
* **** * is an impossible * * * *



return 0;

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



int main()

{
** * * * * * * * * h, n, m, i, day, num, num1, num2, num3, num4, num5;
* * * ****** ** * * * ** ** ** * ** &h, &n, &m, &i);
*** * ** * ** * = h - i - n;
* **** * * * * * ** = n - m;
* ** * *** ** = num / num1;
** * **** ***** ** = num2 + 1;
* ****** ** * ** * = num % num1;
** *** ***** = num2 + 2;
* ** * * * ***** * <= * ** * * * > 0))
** ****** ************ is ** * ** *
** *** * * * *** * * * if(num <= 0)
** * *** * ** * *
** ******* * * * * *** * * *** * ** * **** * * * * *
**** * * ** **
** ** ** * ** ** ** * **** ** if(num4 == 0)
*** ***** *** * * * **
****** ** * ** * ******* * * * * * ** * ** * * * * ** * num3);
***** * ** * *** *
**** * *** **** *
*** ** *** *
**** ** **** * ** * ** * ** * *** * * ** * * ** num5);
* *** * ** *








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

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



int main()

{
* * ** * * * * h, n, m, i, day, num, num1, num2, num3, num4, num5;
** ** * ** ** * ** ** ** &h, &n, &m, &i);
** * * ** * * *** **** = h - i - n;
***** * **** ** = n - m;
** * * **** * * ** * = num / num1;
* *** * * * ** * = num2 + 1;
* ***** * ***** = num % num1;
* ** * * ** * ** ** * = num2 + 2;
* * * * * ** * ** * <= ** ** * * * > 0))
* ** ** * * *** is ** * * * ** *
* * * ** * ** * * * if(num <= 0)
* **** **** *** ** *
* **** * **** * **** * * * ** ** *** * **
* ** * * ***** *
* *** * * * *** ** ** * * if(num4 = 0)
* *** * * *** *
*** ** * * * * * **** * * * * * * * * ** num3);
** * * ** * ***** *
* * ** * * **
****** * * * * *
***** ** * ** ** ***** * *** **** * * ** * * * * num5);
* **** * **** **








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

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



int main(){
** *** * **** * * ** ** h, n, m, i, d = 1, a;
* **** * * **** * *** *** **** * * * * &h, &n, &m, &i);
** * * * *** * * * ** * * *** * ** h, n, m, i);




** * * ** * * * ** * * <= 0)
*** * *** * ** *** ** *** ** * * ** * * * *** *** * ** is impossible!\n");
* ** ** * * * if(h==i)
* **** * ** ** **** * **** * ** ** **** ** * * **
* **** * ***** *
** * * ***** *** * = 0;  a < 4096; a++){
* ** * *** * * *** * * * *** ** * * *** * + n >= h)
**** * ** * * * *** ** * * * *** ** * ** ** * ** * ** **** = d;
* * ** **** *** *** * ** ** ***** * * * **
* * * * * * ** *** ***** *** * * ** * * *** * ** * = i + n - m;
* * *** **** ** **** ** **** * ** * ** ** * * ** ***** *** * ** * *
***** * ** ** ***** * **** ** * *
** ** ******* * *
** * *** ** * * ** * * * ** ** d);
* * * *** ** * * *



return 0;

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

// Created by HoMingJui on 2016/01/5.

//



#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <math.h>





int main(){

    int h,n,m,i,t=0,flag=0;
* * ***** *** **** * ** ** * **** ** %d %d *** *** ** * ** *** ******** ***


* * * ***** ** *** * * * * * || m==n){
* ** ** ** * ** *** * *** * ** *** **** * **** is impossible!");

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

    }




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

}
answered by (-126 points)
0 like 0 dislike
Hidden content!
//

// Created by HoMingJui on 2016/01/5.

//



#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <math.h>





int main(){

    int h,n,m,i,t=0,flag=0;
* * ** * ** ** ** * ** *** %d %d ******* ** * ** ** * * * * **


** * * *** * * * ** * **** * ** * * **
*** * * * ** * **** * * * ** * ** * ** * ** * *** *** ***** ** is impossible!");

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

    }




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

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



int main(){
** * * * *** *** * * h, n, m, i, d = 1, a;
** * * * * * * * * * *** &h, &n, &m, &i);
* *** * ***** *** *** * ** **** ** * * *** h, n, m, i);




* * * ** * * * **** ** ** * * <= 0)
* ** * * *** ** * * * *** * * ** * *** is impossible!\n");
* **** * * *** * *** * * ** = 0;  a < 4096; a++){
** ** * * ** * *** **** ** ***** * **** **** * + n >= h)
* * * ****** ** *** * ** * * ** ******* * *** * ***** ** *** = d;
* * * * * * * * * *** * * ** *** ** * * ** ** *
* * * * * * * * * * * * * *** * * * ** ** * * ** * = i + n - m;
* * **** * * * * * * ** * * **** **** ** * * * * ** * * * ****** * ** **
* * * * * * * *** **** * * *** * *
*** * * ** * * *
*** * * * ** *** ** ** *** ***
** ** *** **** * * *** ** ** * **** * *** ** * ** * * d);



return 0;

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

Related questions

0 like 0 dislike
3 answers
[Exercise] Essay (Open question) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20995 - Available when: Unlimited - Due to: Unlimited
| 482 views
0 like 0 dislike
28 answers
[Exercise] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20984 - Available when: Unlimited - Due to: Unlimited
| 1.8k views
0 like 0 dislike
43 answers
[Exercise] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20980 - Available when: Unlimited - Due to: Unlimited
| 2.6k views
0 like 0 dislike
39 answers
[Exercise] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20978 - Available when: Unlimited - Due to: Unlimited
| 2.4k views
0 like 0 dislike
16 answers
[Exercise] Essay (Open question) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20974 - Available when: Unlimited - Due to: Unlimited
| 1.3k views
12,783 questions
183,443 answers
172,219 comments
4,824 users