#include<stdio.h>
#include<math.h>
int main(){
int year;
char twelve[12][16]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
while(scanf("%d",&year)){
if(year<0){
abs(year);
printf("%s",twelve[(12-year)%12]);
}
else
printf("%s",twelve[(year-1)%12]);
}
}
#include
#include
int main(){
int year;
char twelve[12][16]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
while(scanf("%d",&year)){
if(year<0){
abs(year);
printf("%s",twelve[(12-year)%12]);
}
else
printf("%s",twelve[(year-1)%12]);
}
}
while(scanf("%d",&year)!=EOF)
#include
#include
int main(){
int year;
char twelve[12][16]={"鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬"};
while(scanf("%d",&year)){
if(year<0){
abs(year);
printf("%s",twelve[(12-year)%12]);
}
else
printf("%s",twelve[(year-1)%12]);
}
}while(scanf("%d",&year)!=EOF)
#include<iostream>
using namespace std;
int main(int argc, char** argv)
{
int n;
cin>>n;
cout<<n;
}
試試輸入ctrl + z鍵,看回傳的值
cin通常是碰到End of file 或是手動輸入^Z (ctrl + z)就會停止
如果是scanf() 要看他回傳值等不等於EOF
所以要while(scanf("%d",&year)!=EOF)