# [C語言] a864. 4. Stellar Classification ## C語言 ## 觀念: 1. scanf會怎麼看待空格和怎麼處理空格後的東西? "scanf() 讀字串時遇到空格就會斷開,而如果有剩下的部分,會被留在緩衝區裡等待下一次的 scanf()。" "想要連同空格一起吃入字串的話,可以用fgets()。"[[2]](https://25349023.github.io/articles/2021-02/c-str-0/) ## AC程式碼: ``` #include<stdio.h>/* for printf and scanf */ #include<stdlib.h> #include<string.h>/* for strcmp */ int main(){ char n[1000]= {'\0'}; float mB=0,mV=0,a=0; while(scanf("%s",n)!=EOF){ if(strcmp(n,"END")==0){ break; } scanf("%f %f",&mB,&mV); a=mB-mV; if(a>=-0.35&&a<=-0.251){ printf("%s %.2f O\n",n,a); } else if(a>=-0.25&&a<=-0.001){ printf("%s %.2f B\n",n,a); } else if(a>=0.00&&a<=0.249){ printf("%s %.2f A\n",n,a); } else if(a>=0.250&&a<=0.499){ printf("%s %.2f F\n",n,a); } else if(a>=0.500&&a<=0.999){ printf("%s %.2f G\n",n,a); } else if(a>=1.0&&a<=1.499){ printf("%s %.2f K\n",n,a); } else if(a>=1.5&&a<=2.0){ printf("%s %.2f M\n",n,a); } } return 0; } ``` Reference: [1] [a864. 4. Stellar Classification](https://zerojudge.tw/ShowProblem?problemid=a864) [2] [[C] 每天來點字串用法(基本篇)](https://25349023.github.io/articles/2021-02/c-str-0/)