2008年6月29日 星期日

Windows 關閉自動執行 (Autorun) 功能

根據 避免隨身碟病毒,只需 1 招 ,之前常見的一些預防隨身碟病毒的方法,像是 以右鍵開啟隨身碟…似乎都沒有太大效用,網路上另外找到一個方法,不知道有沒有用,反正多一層保護也沒差,根本之道還是要培養良好的電腦使用習慣,才能避免中毒。


1. 開始 -> 執行 -> regedit

2. 找到 「 HKEY_CURRENT_USER\Software\microsoft\Windows\
CurrentVersion\Explorer\MountPoints2 」

3. 按右鍵選擇 「使用權限

4. 新增使用者 Everyone

5. 完全控制權限設定為「拒絕

資料來源:
http://xzjiang.blogspot.com/2008/06/windows-autorun.html

本文依原文授權採

姓名標示-非商業性-相同方式分享 2.5 台灣授權條款

2008年6月24日 星期二

ASCII control characters


reference:wikipedia - ASCII control characters

以後要輸出 new line 時,就只要 putchar(10); 就好了,比 printf 少打很多字 XDD~

scanf("") - 參

input case:存在 input.txt 內
1

RSAEIO
2
5
RTSSKAEAGE

程式碼:
#include <stdio.h>

int main(){

freopen("input.txt","r",stdin);
char input;
while(input!='5'){
scanf("%c",&input);
printf("%d - \t %c\n",input,input);
}
return 0;
}

output:
49 - 1
10 -

10 -

82 - R
83 - S
65 - A
69 - E
73 - I
79 - O
10 -

50 - 2
10 -

53 - 5

如果把 scanf("%c",&input); 改成
  • scanf("%c ",&input); (%c 後面加空白)
  • scanf(" %c",&input); (%c 前面加空白)
  • scanf("%c\n",&input); (%c 後面加 \n )
  • scanf("\n%c",&input); (%c 前面加 \n )
會得到同樣的 output
49 - 1
82 - R
83 - S
65 - A
69 - E
73 - I
79 - O
50 - 2
53 - 5
更有趣的是,如果將 scanf() 與 gets 合用
#include <stdio.h>

int main(){
freopen("input.txt","r",stdin);
char input,line[50];
while(scanf("%c",&input)!=EOF){
printf("%d - \t %c\n",input,input);
gets(line);
printf("gets - %d\t%c\t",line[0],line[0]);
puts(line);
}
return 0;
}

output 變成:
49 - 1
gets - 0
10 -

gets - 82 R RSAEIO
50 - 2
gets - 0
53 - 5
gets - 0
82 - R
gets - 84 T TSSKAEAGE
因為 scanf() 把第一個字讀進去後,下一個字元是 '\n' ,gets() 讀取到 '\n' 就會停止讀取,並且附加一個 null character 在字串尾端,而這個字串又沒有任何字元,才會出現 line[0]=0 的狀況,如果將原本的 scanf() 改成 scanf("%c ",&input); (%c 後面加上空白),output 就會變成

49 - 1
gets - 82 R RSAEIO
50 - 2
gets - 53 5 5
82 - R
gets - 84 T TSSKAEAGE

input 裡面的 '\n' 都會被跳過,直接讀取一般的字母。

嗯,昨天我在這邊卡了將近一個小時...

2008年6月18日 星期三

701 The Archeologists' Dilemma

題目網頁:http://acm.uva.es/p/v7/701.html

卡了有點久,看了別人解法才發現這題竟然這麼簡單…
公式如下:
N*10^n < 2^k < (N+1)*10^n
log10(N)+n < k*log10(2) < log10(N+1)+n
log10(N) < k*log10(2)-n < log10(N+1)
find if k exist

另外,k 如果最大值設 32,767 (int)會 WA ,如果設成 2,147,483,647 (long)就可以順利 AC