南开100答案1to50终于免费了.docx
《南开100答案1to50终于免费了.docx》由会员分享,可在线阅读,更多相关《南开100答案1to50终于免费了.docx(29页珍藏版)》请在冰豆网上搜索。
![南开100答案1to50终于免费了.docx](https://file1.bdocx.com/fileroot1/2023-6/21/bb0b350d-235c-4881-af5d-72e21e06c742/bb0b350d-235c-4881-af5d-72e21e06c7421.gif)
南开100答案1to50终于免费了
1、intisP(intm)
{inti;
for(i=2;iif(m%i==0)return0;
return1;
}
voidnum(intm,intk,intxx[])
{ints=0;
for(m=m+1;k>0;m++)
if(isP(m)){xx[s++]=m;k--;}
}
无忧id14题(无isP()函数)
#include
voidjsValue(intm,intk,intxx[])
{inti,j,s=0;
for(i=m+1;k>0;i++)
{for(j=2;j
if(i%j==0)break;
if(i==j){xx[s++]=i;k--;}
}
}
另一解法:
voidnum(intm,intk,intxx[])
{
intn=0,data=m+1;
while(nif(isP(data))xx[n++]=data;
data++;}
}
2*、voidjsVal()
{inti,j,qw,bw,sw,gw;
for(i=0;i{qw=a[i]/1000;bw=a[i]/100%10;
sw=a[i]%100/10;gw=a[i]%10;
if(qw&&qw%2==0&&bw%2==0&&sw%2==0&&gw%2==0)
b[cnt++]=a[i];
}
for(i=0;ifor(j=i+1;jif(b[i]
}
3**、voidStrOR(void)
{inti,righto,j,s,k;
chartem[80];
for(i=0;ifor(j=strlen(xx[i])-1;j>=0;j--)
{k=0;
memset(tem,0,80);/*初始化字符串数组tem*/
if(xx[i][j]=='o')/*如果当前字符为'o',进入以下语句*/
{righto=j;/*则将此字符中位置j的值赋给righto*/
for(s=righto+1;stem[k++]=xx[i][s];/*从righto的下一跳开始将其后所有的字符都存入到tem中
for(s=0;sif(xx[i][s]!
='o')tem[k++]=xx[i][s];/*将不是字符'o'的字符全存入到
strcpy(xx[i],tem);/*将当前已处理的字符重新存入当前行xx*/
}
elsecontinue;
}
}解法二:
voidStrOR(void)
{inti;
chara[80],*p;
for(i=0;i{p=strchr(xx[i],'o');
while(p)
{memset(a,0,80);
memcpy(a,xx[i],p-xx[i]);
strcpy(xx[i],p+1);
strcat(xx[i],a);
p=strchr(xx[i],'o');
}
}
}解法三:
voidStrOR(void)
{inti,j;
charyy[80],*p;
for(i=0;ifor(j=0;jif(xx[i][j]=='o')
{memset(yy,0,80);
p=&xx[i][j+1];
strcpy(yy,p);/*将指针p所指向的字符串拷贝到字符串yy中去*/
strncat(yy,xx[i],j);/*将字符串xx[i]中前j个字符连接到yy中*/
strcpy(xx[i],yy);/*将字符串yy重新拷贝到字符串xx[i]中去*/
j=0;/*开始下一次的扫描*/
}
}相关库函数解释:
char*strncat(char*dest,constchar*src,size_tmaxlen)
功能:
将字符串src中前maxlen个字符连接到dest中
相关头文件:
string.h
char*strcpy(char*dest,constchar*src)
功能:
将字符串src拷贝到字符串dest中去
相关头文件:
string.h
4**、voidStrOL(void)
{inti,j,k,s,m,strl;
charstr[80];
for(i=0;i{strl=strlen(xx[i]);
memset(str,0,80);/*初始化这字符串数组str*/
s=k=0;
for(j=strl-1;j>=0;j--)/*从当前字符串尾部开始向前倒序循环,实现题意要求的倒排*/
{if(isalpha(xx[i][j]))k++;/*如果当前字符是字母a~z或A~Z,则k加一*/
else{for(m=1;m<=k;m++)/*否则将长度为k的单词顺序存入到字符串数组str中,s值加1/
str[s++]=xx[i][j+m];
k=0;/*将k值清0,以方便下一个单词的长度计数*/
}
if(!
isalpha(xx[i][j]))str[s++]='';/*如果当前字符不是字母a~z或A~Z,则以空格代之存入到字符串数组str中,s值加一*/
}
for(m=1;m<=k;m++)/*此时的k值为当前字符串中第一个单词的长度,但在上一个for循环中没能存入到字符串数组str中,所以在这里将其存入到str中*/
str[s++]=xx[i][j+m];
str[s]='\0';/*在当前行尾加0以标记此行的结束*/
strcpy(xx[i],str);/*将倒排好的当前字符串重新存回到当前行xx中*/
}
}另一解法():
/*在无忧及捷成版模拟系统中都通过测试(输入文件句末有标点的在输出文件中句前有空格*/
voidStrOL(void)
{inti,j,m;
charstr[80];
for(i=0;i{m=strlen(xx[i]);
memset(str,0,80);
for(j=m-1;j>=0;j--)
if(!
isalpha(xx[i][j]))
{strcat(str,xx[i]+j+1);
strcat(str,"");
xx[i][j]='\0';
}
strcat(str,xx[i]);
strcpy(xx[i],str);
}
5**、voidjsSort()
{
inti,j,data;
for(i=0;i<199;i++)
for(j=i+1;j<200;j++)
if(aa[i]%1000>aa[j]%1000||aa[i]%1000==aa[j]%1000&&aa[i]{data=aa[i];aa[i]=aa[j];aa[j]=data;}
for(i=0;i<10;i++)
bb[i]=aa[i];
}
6、voidjsSort()
{
inti,j,data;
for(i=0;i<199;i++)
for(j=i+1;j<200;j++)
if(aa[i]%1000aa[j])
{data=aa[i];aa[i]=aa[j];aa[j]=data;}
for(i=0;i<10;i++)
bb[i]=aa[i];
}
7*、voidSortDat()
{intI,j;
PROxy;
for(I=0;I<99;I++)
for(j=I+1;j<100;j++)
if(strcmp(sell[I].dm,sell[j].dm)<0||strcmp(sell[I].dm,sell[j].dm)==0&&sell[I].je{xy=sell[I];sell[I]=sell[j];sell[j]=xy;}
}
8**、voidencryptChar()
{inti,j;
for(i=0;ifor(j=0;jif(xx[i][j]*11%256<=32||xx[i][j]*11%256>130)continue;
elsexx[i][j]=xx[i][j]*11%256;
}解法二:
voidencryptChar()
{inti,j,k;
for(i=0;ifor(j=0;j{k=xx[i][j]*11%256;
if(k<=32||k>130)continue;
elsexx[i][j]=k;
}
}解法三:
voidencryptChar()
{inti,j;
unsignedcharch;
for(i=0;ifor(j=0;j{ch=xx[i][j]*11%256;
if(ch<=32||ch>130)continue;
elsexx[i][j]=ch;
}
}解法四:
voidencryptChar()
{inti,j;
char*p;
for(i=0;ifor(j=0;j{p=xx[i][j]*11%256;
if(p<=32||p>130)continue;
elsexx[i][j]=p;
}
}解法五:
voidencryptChar()
{inti;
char*pf;
for(i=0;i{pf=xx[i];
while(*pf!
=0)
if(*pf*11%256<=32||*pf*11%256>130)pf++;
else*pf++=*pf*11%256;
}
}
9**、voidSortCharD(void)
{intI,j,k,strl;
charch;
for(I=0;I{strl=strlen(xx[I]);
for(j=0;jfor(k=j+1;kif(xx[I][j]}
}
10、voidConvertCharA(void)
{inti,j;
for(i=0;ifor(j=0;jif(xx[i][j]=='z')xx[i][j]='a';
elseif(xx[i][j]>='a'&&xx[i][j]<='y')xx[i][j]+=1;
}
11*、voidchg(char*s)
{while(*s)
if(*s=='z'||*s=='Z'){*s-=25;s++;}
elseif(*s>='a'&&*s<='y'){*s+=1;s++;}
elseif(*s>='A'&&*s<='Y'){*s+=1;s++;}
elses++;
}
12*、voidSortDat()
{inti,j;
PROxy;
for(i=0;i<99;i++)
for(j=i+1;j<100;j++)
if(strcmp(sell[i].mc,sell[j].mc)>0||strcmp(sell[i].mc,sell[j].mc)==0&&sell[i].je>sell[j].je)
{xy=sell[i];sell[i]=sell[j];sell[j]=xy;}
}
13*、voidSortDat()
{inti,j;
PROxy;
for(i=0;i<99;i++)
for(j=i+1;j<100;j++)
if(strcmp(sell[i].dm,sell[j].dm)>0||strcmp(sell[i].dm,sell[j].dm)==0&&sell[i].je{xy=sell[i];sell[i]=sell[j];sell[j]=xy;}
}
14*、voidjsVal()
{inti,j,flag;
for(i=0;i{for(j=i+1;j<=i+5;j++)
if(a[i]>a[j]&&a[i]%2)flag=1;
else{flag=0;break;}
if(flag==1){b[cnt]=a[i];cnt++;}
}
for(i=0;ifor(j=i+1;jif(b[i]>b[j]){flag=b[i];b[i]=b[j];b[j]=flag;}
}
15、voidjsVal()
{inti,j;
intqw,bw,sw,gw;
for(i=0;i{qw=a[i]/1000;bw=a[i]%1000/100;
sw=a[i]%100/10;gw=a[i]%10;
if((qw<=bw)&&(bw<=sw)&&(sw<=gw)&&(a[i]%2==0))
b[cnt++]=a[i];
}
for(i=0;ifor(j=i+1;jif(b[i]>b[j]){qw=b[i];b[i]=b[j];b[j]=qw;}
}
16*、voidStrCharJR()
{inti,j;
for(i=0;ifor(j=0;jxx[i][j]+=(xx[i][j]>>4);
}
17*、voidChA(void)
{inti,j;
charch;
for(i=0;i{ch=xx[i][0];
for(j=0;jxx[i][j]+=xx[i][j+1];
xx[i][strlen(xx[i])-1]+=ch;
strrev(xx[i]);
}
}
18*、voidencryptChar()
{inti,j;
for(i=0;ifor(j=0;jif(xx[i][j]*11%256<=32||xx[i][j]%2==0)continue;
elsexx[i][j]=xx[i][j]*11%256;
}
19、intfindStr(char*str,char*substr)
{intn=0;
char*p,*r;
while(*str)
{p=str;
r=substr;
while(*r)
if(*r==*p){r++;p++;}
elsebreak;
if(*r=='\0')
n++;
str++;
}
returnn;
}解法二:
intfindStr(char*str,char*substr)
{inti,j,len1,len2,cnt=0,flag;
len1=strlen(str);
len2=strlen(substr);
for(i=0;i{for(j=0;jif(str[i+j]==substr[j])flag=1;
else{flag=0;break;}
if(flag==1)cnt++;
}
returncnt;
}解法三:
intfindStr(char*str,char*substr)
{inti,cnt=0;
for(i=0;iif(str[i]==*substr&&str[i+1]==*(substr+1))cnt++;
returncnt;
}解法四:
intfindStr(char*str,char*substr)
{intcnt=0;
while(*str)
if(*str==*substr&&*(str+1)==*(substr+1)){cnt++;str++;}
elsestr++;
returncnt;
}
20、intjsValue(intt)
{intf0=0,f1=1,fn;
fn=f0+f1;
while(fn<=t)
{f0=f1;
f1=fn;
fn=f0+f1;
}
returnfn;
}
21、floatcountValue()
{doublex0,x1;
x1=0.0;
do{x0=x1;
x1=cos(x0);
}while(fabs(x0-x1)>=0.000001);
returnx1;
}
22*、doublecountValue(intn)
{inti;
doubles=0.0;
for(i=1;iif(i%21==0)s+=i;
returnsqrt(s);
}
23*、voidCalValue(void)
{inti;
for(i=0;i{sumint+=(long)xx[i];
sumdec+=xx[i]-(long)xx[i];
aver+=xx[i];
}
aver/=N;
}
24*、intjsValue(intbb[])
{inti,j,k=0;
inthun,ten,data;
for(i=100;i<=999;i++)
{j=10;
while(j*j<=i)
{if(i==j*j)
{hun=i/100;data=i%100/10;ten=i%10;
if(hun==ten||hun==data||ten==data)bb[k++]=i;
}
j++;
}
}
returnk;
}另一解法:
intjsValue(intbb[])
{inti,j,cnt=0,bw,sw,gw;
for(i=100;i<=999;i++)
{bw=i/100;sw=i%100/10;gw=i%10;
for(j=10;j*j<=i;j++)
if(i==j*j&&(bw==sw||sw==gw||gw==bw))bb[cnt++]=i;
}
returncnt;
}
25*、intjsValue(longn)
{inti,strl,half;
charxy[20];
ltoa(n,xy,10);/*注意这里不能使用itoa()函数,因为n是long型的*/
strl=strlen(xy);
half=strl/2;
for(i=0;iif(xy[i]!
=xy[--strl])break;
if(i>=half)return1;
elsereturn0;
}或者下面的解法:
intjsValue(longn)
{longints=0,k;
k=n;
while(k)
{s=s*10+k%10;
k/=10;
}
if(s==n)return1;
if(s!
=n)return0;
}输出结果为:
m=11,m*m=121,m*m*m=1331
m=101,m*m=10201,m*m*m=1030301
m=111,m*m=12321,m*m*m=1367631
26*、voidCalValue(void)
{inti,data;
for(i=0;iif(xx[i]>0)
{totNum++;
data=xx[i]>>1;
if(data%2==0){totCnt++;totPjz+=xx[i];}
}
if(totCnt==0)totPjz=0;
elsetotPjz/=totCnt;
}
27*、jsValue()
{inti,j,qw,bw,sw,gw;
for(i=0;i<300;i++)
{qw=a[i]/1000;bw=a[i]/100%10;
sw=a[i]%100/10;gw=a[i]%10;
if(qw-bw-sw-gw>0)b[cnt++]=a[i];
}
for(i=0;ifor(j=i+1;jif(b[i]>b[j]){qw=b[i];b[i]=b[j];b[j]=qw;}
}
28*、voidjsVal()
{inti,j,thou,hun,ten,data,ab,cd;
for(i=0;i<200;i++)
{thou=a[i]/1000;hun=a[i]%1000/100;
ten=a[i]%100/10;data=a[i]%10;
ab=10*thou+ten;cd=10*data+hun;
if((ab-cd)>=0&&(ab-cd)<=10&&ab%2==1&&cd%2==1&&ab>=10&&cd>=10)
b[cnt++]=a[i];
}
for(i=0;ifor(j=i+1;jif(b[i]
}
29*、voidjsVal()
{inti,j,qw,bw,sw,gw,ab,cd;
for(i=0;i{qw=a[i]/1000;bw=a[i]/100%10;
sw=a[i]%100/10;gw=a[i]%