This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
這本來的某考上大學的非資訊社同學問我的,剛好有空就把它整理出來 | |
以下是一些我臨時想到的,歡迎補充。 | |
這些對論壇中大部人已經是基礎了吧~不過我想對下一屆學弟還是有用的。 | |
我自己是習慣用 cin 和 string 來做 input,雖然有些題目真的需要用 scanf 速度上才過得了… | |
但 scanf 跟我不是很熟,怕誤導學弟,就等其它人來寫了。 | |
以下都以例子來說明。 | |
註:這些寫法不是唯一的,存在著許多不同寫法可以有同樣效果。 | |
目錄: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
#include <cstring> | |
#include <iomanip> | |
using namespace std; | |
int build_num(const string s, int* map) { | |
if (s.length() == 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Yu-Cheng Huang 09.24.2014 403410034 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
int max(const int a, const int b) { | |
return ((a > b) ? a : b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <string.h> | |
#include <getopt.h> | |
#include <stdbool.h> | |
int int_data[1000000]; | |
char* str_data[1000000]; | |
void* temp[1000000]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
我想應該很多人寫 uva 時會遇到很多問題,所以我就寫了些教學。 | |
這只是較常見的輸入型式,還存在其它複雜許多的,但大一應該碰不到,我就不一一論述了,有遇到問題的可以問我。 | |
目錄: | |
0. uva 講解。 | |
1. 單筆測資 | |
2. 有給定測資數 | |
3. 多筆測資:單行 | |
4. 多筆測資:多行 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
要求: | |
單筆測資,輸入為一個正整數(保證 int 可存),請輸出這個整數出現次數 2 次以上的數字,並輸出出現的次數。 | |
若沒有任何數字出現 2 次以上,請輸出 "No repeated digit"。 | |
# Sample Input 1 | |
233345 | |
# Sample Output 1 | |
3: 3 | |
# Sample Input 2 | |
12345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
上個教學中使用 flag 的那種技巧是非常非常頻繁地使用的,以下舉幾個簡單例子。 | |
*/ | |
/* | |
題目 1: | |
單筆測資,給你一個長度為 10 的序列,序列中的每一項都是正整數(保證 int 可存),請輸出序列中的最大值。 | |
# Sample Input | |
6 5 4 8 9 3 2 1 7 0 | |
# Sample Output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
#include <ctype.h> | |
#include <time.h> | |
#include <dirent.h> | |
#include <unistd.h> | |
#include <getopt.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
uva 10008 這題應該不是目前學到的知識可以解的…… | |
於是我出來幫助大家了 | |
這份教學分為三個部分(整行讀入(這題不一定要用到)、資料儲存、排序),你必需知道什麼是函式才讀得懂以下內容。 | |
*/ | |
/* | |
第一部分:整行讀入。強列建議使用 fgets。 | |
之前的教學有大約地寫出來,但有很多細節沒講。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
在這題裡我們得計錄各個英文字母出現的次數,要實作這個想法有很多寫法,但一般都用陣列就可以了。(因為英文字母在編碼上是連續的) | |
還記得之前統計數字出現次數的程式吧,現在要做的跟那個類似。 | |
只是陣列的使用上不太一樣。 | |
在進入教學之前你得先有個認知:在 C 中,本質上 char 跟 int 是一樣的,因為每個 char 都有個編碼(ascii) | |
所以我們才能寫出:*/ | |
printf("%c\n", 'a'+1); | |
/* 並得到 'b'。C 會自動幫你處理 char 跟 int 之間的轉換。 | |
另外,ascii 中 |
OlderNewer