程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> first day~,firstday

first day~,firstday

編輯:關於C語言

first day~,firstday


it's been a long time without practicing~ almost everything about the C programming language.

learn today: 1/ read the problem carefully.

                  2/no blank between two input (scanf(“%d %d", &a, &b);

prac: 2001(http://acm.hdu.edu.cn/showproblem.php?pid=2001)

計算兩點間的距離

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 95055    Accepted Submission(s): 36510

Problem Description 輸入兩點坐標(X1,Y1),(X2,Y2),計算並輸出兩點間的距離。   Input 輸入數據有多組,每組占一行,由4個實數組成,分別表示x1,y1,x2,y2,數據之間用空格隔開。   Output 對於每組輸入數據,輸出一行,結果保留兩位小數。   Sample Input 0 0 0 1 0 1 1 0   Sample Output 1.00 1.41   Author lcy   Source C語言程序設計練習(一)   Recommend JGShining   |   We have carefully selected several similar problems for you:  2003 2002 2004 2000 2005     first try: output limit exceeded  
#include<stdio.h>
#include<math.h>

int main(){
    int x1, y1, x2, y2;
    double result;
    while(scanf("%d %d %d %d", &x1, &y1, &x2, &y2)!=EOF){
        result = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
        printf("%.2f\n", result);
    }
    return 0;
}


why?:題目的輸入格式中明確說明了每組測例的輸入是4個實數,而不是4個整數。scanf("%d", &n);這樣的寫法,在輸入中有非數字和空格的字符出現時,讀入會失敗,但不報錯,也不會跳過失敗處的字符。所以樓主的程序在遇到第一個小數點的時候就一直重復輸入最後一次正確讀入的測例的結果了,最終造成輸入超限。

 

second try: accepted

#include<stdio.h>
#include<math.h>

int main(){
    double x1, y1, x2, y2, result;
    while(scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2)!=EOF){
        result = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
        printf("%.2lf\n", result);
    }
    return 0;
}

 


the first day 與at the first day有什不同?

你要是想說,在第一天裡我做了什麼什麼~~~就是at the first day在句尾~~~開頭的話用the first day有點別扭- -
 

英文寫作,題目:My First Day in the University ,助

  My first day at university
  It was at 10th September that I come to my university. The first impression of this campus was the beautiful scenery. Green trees and colorful flowers could be seen everywhere. Besides, modern teaching buildings stand in the center of our campus. Surrounding those well-designed buildings lie several limpid lakes. Opposite the lakes ,our dormitories are orderly arranged. In the morning, I looked around our teaching buildings. Each classroom is wide ,bright and equipped with advanced facilities.

The volunteers at the receptionist were all passionate and considerate. The services they provided for me were of high quality. A senior student introduced a lot of rules and living structures to me. I took part in the “Communication Meeting Between Freshmen And Senior Students”. I had a good time there and met lots of new friends. After finishing the procedure of my enrollment, I went straight to my dormitory. Although my room is not spacious, its comfortable and made me feel at home. My luggage was so heavy. I was nearly exhausted for carrying the big suitcase, but that didn’t quench my excitement because the imagination of mycolorful college life was always with me. In the afternoon, I had a comprehensive visit of my university following the introduction regiment. The strong learning atmosphere in the library really impressed me. Seeing those senior students immersed in study, I set a lofty ideals and high aspirations that in the university I must stu......余下全文>>
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved