[Luogu] P3469 [POI2008]BLO-Blockade
阿新 • • 發佈:2020-11-02
// 1 .cpp #include <stdio.h> int main(){ int a=5, b=7, c=100, d, e, f; d=a/b*c; e=a*c/b; f=c/b*a; printf("d=%d, e=%d, f=%d\n",d,e,f); return 0; }
a/b*d
a*c/b
c/b*a
整數的除法結果為整數
// ! #include <stdio.h> int main(){ int x=1234; float f=123.456; doublem=123.456; char ch='a'; char a[]="Hello,world!"; int y=3, z=4; printf("%d %d\n",y,z); printf("y=%d, z=%d\n",y,z); printf("%8d,%2d\n",x,x); printf("%f,%8f,%8.1f,%0.2f,%.2e\n",f,f,f,f,f); printf("%1f\n",m); printf("%3c\n",ch); printf("%s\n%15s\n%10.5s\n%2.5s\n%.3s\n",a,a,a,a,a); return 0; }
d輸出整數
8d小數點前有八位
f輸出浮點數小數點後有六位
8f從左向右八位不足補空
8.1小數點後只有一位
.e小數點後兩位且十進位制
lf輸出長浮點數
3c輸出一個字元有三位
s輸出一個字串
//4 //判斷 #include <stdio.h> int main(){ char x; x=getchar(); if(x>=48&&x<=57) printf("%c是數字字元\n",x); else if(x>=65&&x<=90||x>=97&&x<=122) printf("%c是英文字元\n",x); else printf("%c是其它字元\n",x); return 0; }
//5 #include <stdio.h> int main() { char ans1, ans2; printf("複習了沒?(輸入y或Y表示複習了,輸入n或N表示沒複習):"); ans1 = getchar(); getchar(); printf("\n動手敲程式碼了沒?(輸入y或Y表示敲了,輸入n或N表示木有敲):"); ans2 = getchar(); if((ans1=='y'||ans1=='Y')&&(ans2=='y'||ans2=='Y')) printf("\n羅馬不是一日建成的:)\n"); else printf("羅馬不是一天毀滅的。。。\n"); return 0; }
//6 #include <stdio.h> #include <math.h> int main (){ int n,sum,q=2; scanf("%d",&n); sum=1*(1-pow(q,n))/(1-q); printf("當n = %d時,sum = %d\n",n,sum); return 0; }
//小人 #include <stdio.h> int main(){ int n=0; char ch='I'; char a[ ] ="<H>"; printf("%2d\n""%s\n""%c %c\n",n,a,ch,ch); return 0; }
學會了格式符的用法,輸出,列印的規則。小人的排列,個位列印還是要多加練習。