南開第19題:
編寫一個函數(shù)findstr(),該函數(shù)統(tǒng)計一個長度為2的子字符串在另一個字符串中出現(xiàn)的次數(shù)。例如:假定輸入的字符串為"asd asasdfg asd as zx67 asd mklo",子字符串為"as",函數(shù)返回值為6。
函數(shù)readwriteDat()的功能是實(shí)現(xiàn)從文件in.dat中讀取兩個字符穿4,并調(diào)用函數(shù)findstr(),最后把結(jié)果輸出到文件out.dat中。
注意:部分源程序已給出。
請勿改動主函數(shù)main()和函數(shù)ReadWrite()的內(nèi)容。
-----------------------
int findStr(char *str,char *substr)
{
/*請參考南開100題*/
}
南開第2題:整數(shù)排序題
#include
#define MAX 200
int a[MAX], b[MAX], cnt = 0 ;
void jsVal()
{ int i,j,qw,bw,sw,gw;
for(i=0;i { qw=a[i]/1000; bw=a[i]/100;
sw=a[i]0/10; gw=a[i];
if(qw&&qw%2==0&&bw%2==0&&sw%2==0&&gw%2==0) b[cnt++]=a[i];
}
for(i=0;i for(j=i+1;j if(b[i]}
void readDat()
{
int i ;
FILE *fp ;
fp = fopen("in.dat", "r") ;
for(i = 0 ; i < MAX ; i++) fscanf(fp, "%d", &a[i]) ;
fclose(fp) ;
}
void main()
{
int i ;
readDat() ;
jsVal() ;
printf("滿足條件的數(shù)=%d\n", cnt) ;
for(i = 0 ; i < cnt ; i++) printf("%d ", b[i]) ;
printf("\n") ;
writeDat() ;
}
writeDat()
{
FILE *fp ;
int i ;
fp = fopen("out.dat", "w") ;
fprintf(fp, "%d\n", cnt) ;
for(i = 0 ; i < cnt ; i++) fprintf(fp, "%d\n", b[i]) ;
fclose(fp) ;
}
編寫一個函數(shù)findstr(),該函數(shù)統(tǒng)計一個長度為2的子字符串在另一個字符串中出現(xiàn)的次數(shù)。例如:假定輸入的字符串為"asd asasdfg asd as zx67 asd mklo",子字符串為"as",函數(shù)返回值為6。
函數(shù)readwriteDat()的功能是實(shí)現(xiàn)從文件in.dat中讀取兩個字符穿4,并調(diào)用函數(shù)findstr(),最后把結(jié)果輸出到文件out.dat中。
注意:部分源程序已給出。
請勿改動主函數(shù)main()和函數(shù)ReadWrite()的內(nèi)容。
-----------------------
int findStr(char *str,char *substr)
{
/*請參考南開100題*/
}
南開第2題:整數(shù)排序題
#include
#define MAX 200
int a[MAX], b[MAX], cnt = 0 ;
void jsVal()
{ int i,j,qw,bw,sw,gw;
for(i=0;i { qw=a[i]/1000; bw=a[i]/100;
sw=a[i]0/10; gw=a[i];
if(qw&&qw%2==0&&bw%2==0&&sw%2==0&&gw%2==0) b[cnt++]=a[i];
}
for(i=0;i for(j=i+1;j if(b[i]}
void readDat()
{
int i ;
FILE *fp ;
fp = fopen("in.dat", "r") ;
for(i = 0 ; i < MAX ; i++) fscanf(fp, "%d", &a[i]) ;
fclose(fp) ;
}
void main()
{
int i ;
readDat() ;
jsVal() ;
printf("滿足條件的數(shù)=%d\n", cnt) ;
for(i = 0 ; i < cnt ; i++) printf("%d ", b[i]) ;
printf("\n") ;
writeDat() ;
}
writeDat()
{
FILE *fp ;
int i ;
fp = fopen("out.dat", "w") ;
fprintf(fp, "%d\n", cnt) ;
for(i = 0 ; i < cnt ; i++) fprintf(fp, "%d\n", b[i]) ;
fclose(fp) ;
}