1001【答案】
#include
int main(){
int n;int i=0;
scanf("%d",&n);
while(n!=1){
if(n%2==0)
n/=2;
else
n=(n*3+1)/2;
i++;
}
printf("%d",i);
}
1002【答案】
#include
void print(int a){
switch (a){
case 0:
printf ("ling");
break;
case 1:
printf ("yi");
break;
case 2:
printf ("er");
break;
case 3:
printf ("san");
break;
case 4:
printf ("si");
break;
case 5:
printf ("wu");
break;
case 6:
printf ("liu");
break;
case 7:
printf ("qi");
break;
case 8:
printf ("ba");
break;
case 9:
printf ("jiu");
break;
default:
break;
}
}
int main(){
char num[105];
int sum=0;int i = 0;
int hund = 0,dec = 0,unit = 0;//百、十、个
scanf("%s",num);
for(;num[i]!='\0';i++){
sum += (num[i]-'0');
}
//printf("%d",sum);
if(sum>=100){
unit = sum % 10;
//printf("%d ",unit);
dec = (sum/10)%10;
//printf("%d ",dec);
hund = sum/100;
//printf("%d ",hund);
print(hund);
printf(" ");
print(dec);
printf(" ");
print(unit);
} else if(sum >= 10){
unit = sum%10;
dec = sum / 10;
print(dec);
printf(" ");
print(unit);
}else {
unit = sum;
print(unit);
}
return 0;
}
1003【答案】
#include
int Judge(char ch[]){
int i=0;int tag = 1;int T_time=0,P_time=0;
int A_time_front=0,A_time_last=0;
int A_time_mid =0;
int A_time=0;
while(ch[i]!='\0'){
if(ch[i]!='A'&&ch[i]!='P'&&ch[i]!='T'){
tag=0;
break;
}//字符串中必须仅有P,A,T三种字符
else if(ch[i]=='P'){
P_time++;
if(P_time!=1){
tag=0;
break;
}//记录P的个数
}else if(ch[i]=='T'){
T_time++;
if(P_time==0||T_time!=1){
tag = 0;
break;
}
} //T的个数
else if(ch[i]=='A'){
A_time++;
if(P_time==0){
A_time_front++;
} else if(P_time==1&&T_time==0){
A_time_mid++;
}else if(P_time==1&&T_time==1){
A_time_last++;
}
}
i++;
}
if(P_time==0||T_time==0||A_time==0)
tag=0;
else if(A_time_front!=0&&A_time_last!=0){
if((A_time_last/A_time_front)!=(A_time_mid))
tag=0;
}
return tag;
}
int main(){
int n,i=0;
char s[105];
int result[15];
scanf("%d",&n);
for(;iscanf("%s",s);
result[i]=Judge(s);
}
for(i=0;iif(result[i])
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
1004 【答案】
#include
#include
typedef struct student ST;
struct student{
char name[15];
char stunumber[15];
int score;
};
int main(){
ST T;
int n;int i=0;
char name_max[15];
char name_min[15];
char stunumber_max[15];
char stunumber_min[15];
int score_max=-1,score_min=101;
scanf("%d",&n);
for(;iscanf("%s%s%d",T.name,T.stunumber,&T.score);
if(score_maxmemcpy(name_max,T.name,sizeof(T.name));
memcpy(stunumber_max,T.stunumber,sizeof(T.stunumber));
score_max=T.score;
}if(score_min>T.score){
memcpy(name_min,T.name,sizeof(T.name));
memcpy(stunumber_min,T.stunumber,sizeof(T.stunumber));
score_min=T.score;
}
}
printf("%s %s\n",name_max,stunumber_max);
printf("%s %s\n",name_min,stunumber_min);
return 0;
}
1005【答案】
//将数组全部置为零,(1-100)中需要判断的数作为下标,将其置为1
//被覆盖的数作为下标,改其值为0,这样子剩下的值为1的下标就是关键数
//再逆序输出,就是从大到小输出了
#include
int main(){
int cover[105]={0};
int position[105]={0};
int n,tag;
int first=1;
scanf ("%d",&n);
int i=0;
for(;i"%d",&position[i]);//这里由于是数,所以前面要用&
cover[position[i]]=1;
}
for(i=0;iwhile(tag!=0&&tag!=1){
if(tag%2==0)
tag = tag/2;
else
tag = (3*tag+1)/2;
if(tag<=100)
// printf("%d ",tag);
cover[tag]=0;
}
}
for(i=104;i>=0;i--){
if(cover[i]==1)
if(first){
printf("%d",i);
first = 0;
}
else{
printf(" %d",i);
}
}
return 0;
}
1006 【答案】
#include
int main(){
int B;int S;int G;
int n;
int i=0;
scanf("%d",&n);
B = n/100;
S = (n-100*B)/10;
G = (n-100*B-10*S);
for(;iprintf("B");
for(i=0;iprintf("S");
for(i=1;i<=G;i++)
printf("%d",i);
return 0;
}
1007 【答案】
#include
int judge(int a){
int i=2;int tag=1;
for(;i*i<=a;i++){
if(a%i==0){
tag=0;
break;
}
}
return tag;
}
int main(){
int n;int time=0;
scanf("%d",&n);
int i=3;
for(;i<=n-2;i++){
if(judge(i)&&judge(i+2))
time++;
}
printf("%d",time);
}
1008 【答案】
#include
int main(){
int N,M;
int i=0;int first=1;
int num[105];
scanf("%d%d",&N,&M);
for(;i"%d",&num[i]);
}
int time = --i; //关键
while(M--){
int tag=num[time];//关键
i = time; //关键
for(;i>0;i--)
num[i]=num[i-1];
num[0]=tag;
}
for(i=0;iif(first){
printf("%d",num[i]);
first=0;
}else
printf(" %d",num[i]);
return 0;
}
1009 【答案】
//关于字符串指针数组应该好好研究一下
#include
#include
#include
char ch[90];
int main(){
int position[40];
int i=0;int j,k=1;
while((ch[i++]=getchar())!='\n');
i--;
ch[i]='\0';
position[0]=0;
for(j=0;jif(ch[j]==' '){
ch[j]='\0';
position[k++]=j+1;
}
int first=1;
for(i=k-1;i>=0;i--){
if(first){
printf("%s",&ch[position[i]]);
first=0;
}else{
printf(" %s",&ch[position[i]]);
}
}
return 0;
}
1010 【答案】
#include
int main(){
int position;int number,max=0;
int a[1005]={0};//记着初始化
int i=0;
scanf("%d%d",&number,&position);
if(position>0){
max = position-1;
a[position-1]=number*position;
}else{
a[0]=0;
}
int tag=position-1;
while(tag>0){
scanf("%d%d",&number,&position);
if(position>0){
a[position-1]=number*position;
}
tag--;
}
int first=1;
for(i=max;i>=0;i--){
if(a[i]!=0){
if(first){
printf("%d %d",a[i],i);
first=0;
}else
printf(" %d %d",a[i],i);
}
}
if(first)
printf("0 0");
return 0;
}
1011 【答案】
//注意数据大小,如果超过long的-2^31 ~ 2^31 - 1
//就要使用字符数组来计算数字加减乘除了
#include
int main(){
long a,b,c;
int p[11]={0};
int n,j,i=0;
scanf("%d",&n);
while(n--){
scanf("%ld%ld%ld",&a,&b,&c);
if((a+b)>c)
p[i++]=0;
else
p[i++]=1;
}
for(j=0;jif(p[j]==0)
printf("Case #%d: true\n",j+1);
else
printf("Case #%d: false\n",j+1);
}
return 0;
}
1012 【答案】
#include
int num[1005]={0};
int N;
void A1(int n);
void A2(int n);
void A3(int n);
void A4(int n);
void A5(int n);
int main(){
scanf("%d",&N);
int i=0;
for(;i"%d",&num[i]);
A1(N);
A2(N);
A3(N);
A4(N);
A5(N);
return 0;
}
void A1(int n){
int i=0;int sum=0;
for(;iif(num[i]%2==0&&num[i]%5==0)
sum+=num[i];
if(sum!=0)
printf("%d",sum);
else
printf("N");
}
void A2(int n){
int i=0;int sum=0;int time=0;int tag=1;
for(;iif(num[i]%5==1){
sum+=(num[i]*tag);
time++;
tag*=-1;
}
if(time!=0)
printf(" %d",sum);
else
printf(" N");
}
void A3(int n){
int tag=0;
int i =0;
for(;iif(num[i]%5==2)
tag++;
if(tag)
printf(" %d",tag);
else
printf(" N");
}
void A4(int n){
int sum=0;
float average =0;
int tag=0,i=0;
for(;iif(num[i]%5==3){
sum+=num[i];
tag++;
}
if(tag==0)
printf(" N");
else {
average = (float)sum/tag;/*要先将sum转换为float,不然答案直接去掉小数部分*/
printf(" %.1f",average);
}
}
void A5(int n){
int tag=0,max=0,i=0;
for(;iif(num[i]%5==4){
tag++;
if(maxif(tag)
printf(" %d",max);
else
printf(" N");
}
1013 【答案】
#include
int prime[10005]={0};
void judge(int a){
int k=3;
int i;
int tag=1;
int temp;
int j=2;
while(tag1;
i = 2;
for(;i*i<=k;i++)
if(k%i==0)
temp=0;
if(temp){
tag++;
prime[j++]=k;
}
k++;
}
}
int main(){
int N,M;int i=1;int posi=1;int first=1;
prime[0]=1;
prime[1]=2;
scanf("%d%d",&N,&M);
judge(M);
for(;N<=M;N++){
if(posi%10!=0&&first==1){
printf("%d",prime[N]);
first=0;
posi++;
}else if(posi%10==0){
printf(" %d\n",prime[N]);
first=1;
posi++;
}else if(posi%10!=0&&first!=1){
printf(" %d",prime[N]);
posi++;
}
}
return 0;
}