1 / 42

介紹 UVa & I/O

介紹 UVa & I/O. 介紹 U Va & ICPC & NCPC I/O 資料型態 I/O 範例 程式技巧. Coding 突破. 什麼是 ACM?. ACM=Association of Computing Machinery 美國計算機協會. 註冊 UVa . 跟著做 http://uva.onlinejudge.org/. What are ICPC & NCPC. ICPC= International Collegiate Programming Contest

urban
Télécharger la présentation

介紹 UVa & I/O

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 介紹 UVa & I/O

  2. 介紹 UVa & ICPC & NCPC I/O 資料型態 I/O 範例 程式技巧 Coding突破

  3. 什麼是 ACM? • ACM=Association of Computing Machinery • 美國計算機協會

  4. 註冊 UVa • 跟著做 • http://uva.onlinejudge.org/

  5. What are ICPC & NCPC ICPC= International Collegiate Programming Contest = 國際大專體設計競賽 NCPC=全國大專軟體設計競賽

  6. 你可能得到的結果 • Judge Situation • Accept (AC) 接受(通過) • Presentation Error (P.E.) 格式錯誤 • Wrong Answer (WA) 錯誤答案 • Time Limit Exceeded (TLE) 超過時間 • Memory Limit Exceeded (MLE) 超過記憶體上限 • Output Limit Exceeded (OLE) 超過輸出上限 • Compile Error (CE) 編譯錯誤 • Submission Error (SE) 提交錯誤 • Runtime Error (RE) 執行錯誤 • Restricted Function (RF) 使用禁止函式

  7. 資料型態

  8. I/O 型態

  9. C Input Output

  10. scanf(“%c”,&input);

  11. output 是int: printf(“%d\n”,output); printf(“%3d\n”,output); printf(“%-3d\n”,output); printf(“%03d\n”,output); output是int: printf(“%f\n”,output); printf(“%2.3f\n”,output);

  12. output是char或是int : printf(“%c\n”,output); printf(“%d\n”,output); string是char的陣列 printf(“%s\n”,string); // string is char[]

  13. 實驗看看吧!!

  14. 第一次 AC.10055一起完成吧!!

  15. I/O 範例

  16. 讀到檔案結束 while(scanf(“%d”,&input)!=EOF){ //code } 條件式結束 while(scanf(“%d”,&input) && input != 0 ){ //code } 已知有幾筆測資 while(datas--){ //code }

  17. 陣列大小要注意~~ int number[10]; for(int counter=1 ;counter<=10 ;counter++){ scanf(“%d”,&number[counter]); } 當 counter=10 就會發生錯誤

  18. 字元是以ASCII 做運算 char code; // 有一個密碼 code = ‘a’; // 他是a code+= 3; // 加3後 printf(“%c”,code); 將會印出d

  19. The second AC 458

  20. 苦工題 switch 是好朋友 switch 版: switch(){ case ‘ ‘: ….. case ‘ ‘: } if 版: if(){ }else{ if(){ }else{ …….. } } 記得要加break喔!!

  21. 善用strcmp strcmp( string1,string2); //比較兩字串 strcmp( string , “command\0”); // 看string 是不是command warning1 : 要有#include<string.h>

  22. strcmp 的回傳值 strcmp的回傳值為 • 前者的字典排序小於後者時 回傳負數 • 當前者的字典排序等於後者時 回傳零 • 當前者的字典排序大於後者時 回傳正數

  23. Tips about programming • 好習慣 • 測資很奸詐 • 註解 • CMD

  24. 好習慣

  25. 變數要有意義 int sasdf; int sdfdf; int eafesgf; scanf(“%d%d”,&sasdf,& sdfdf); eafesgf = sasdf + sdfdf ; // 久了你自已都不知這是什麼 int number1; int number2; int sum; scanf(“%d%d”,&number1,&number2); sum = num1 + num2;

  26. 記得要排版 有排版 while( ){ for(){ sum+=1; } counter++; } 沒排版 while(){ for() { sum+=1; } counter++ } // 是不是比較難讀了?

  27. 變數不能沒有值 錯誤範例 : //找最大的數 int input; int biggest; while(scanf(“%d”,&input)!=EOF){ if(biggest<input) biggest = input ; } // 程式第一次執行會出問題

  28. 變數周期要注意 錯誤例: for(int sum=0, i =0 ; i <10 ; i ++){ sum += i ; } printf(“%d\n”,sum);

  29. 測資很奸詐!!

  30. 註解有利找出程式的錯誤

  31. CMD 測資處理 • windows的cmd檔案IO的功能 • 指令: • test<input.txt <enter> 從檔案input讀入test.exe執行 • test>output.txt <enter> 把你在test.exe所print的結果存到output.txt中 混用法 test<input.txt>output.txt <enter>

  32. 實做一次看看吧

  33. 參考資料 • 2009年講議 • <C How to pragram>

  34. 練習一下吧!!! • 基本題 • 272 • 10071 • 10209 //float 不夠準喔~~ • 進階題 • 591 • 10222

  35. 補充 C++

  36. C++ IO • tip : #include<iostream> • using namespace std; • Input • cin ex:cin>>num1>>num2; = scanf(“%d %d”,&num1,&num2);

  37. cin about string • cin.get() • Ex: char test; • cin.get(test); • cin.getline(); • Ex: char test[10]; • cin.getline(test,9,’\n’); • Ps:最後的參數為斷句的key char

  38. cout • cout • Ex:int n1=0,n2=1; • cout<<“n1=”<<n1<<“n2=”<<n2<<endl; • 可以不需設定type!

  39. cout tips • cout.setprecision() • #include <iomanip> • double n=3.14159; cout << setprecision(2) <<fixed << n<<endl; //輸出n到小數點下2位

  40. cout tips • cout.width(); • Ex: printf(“%-10d\n”,a); printf(“%10d\n”,a); = cout.width(10); cout<<left<<a<<endl; cout<<right<<a<<endl;

  41. cout tips • cout.fill(); • Ex: printf(“%010d\n”,a); = cout.width(10); cout.fill(‘0’); cout<<right<<a<<b<<endl;

More Related