Description
請撰寫一個程式,讓使用者輸入一個檔案名稱,並且確認該檔案檔名是否為 c。
Please write a program that allows the user to enter a file name and confirm whether the file name is c.
Input
輸入包含一個字串�s,�s的長度≤15≤15,字串的結尾一定是某個檔名。
The input contains a string �s, the length of �s is ≤10≤10, and the end of the string must be a certain file name.
Output
若檔名為 c 請輸出 yes
若檔名不為 c 請輸出 no
If the file name is c, please output yes
If the file name is not c, please enter no
Sample Input 1
main.c
Sample Output 1
yes
Sample Input 2
main.cpp
Sample Output 2
no
#include <stdio.h>
int main()
{
char n[10];
int counter = 0;
scanf("%s", &n);
for(int i = 0; i<=10;i++){
if((int)n[i]=='.'){
counter++;
if((int)n[i+1]=='c'){
counter++;
if((int)n[i+2]<=0){
counter++;
}
}
}
}
if(counter>=3){
printf("yes");
}else{
printf("no");
}
return 0;
}