C語言程式求debug 統計字串在另字串中出現的

2021-04-21 16:00:43 字數 4705 閱讀 9496

1樓:凌亂心扉

//第一種

public static map count(string str)

}return maps;

}//第二種

public static map count1(string str)

return map;

}//第三種

public static map count2(string str)

}map.put(c1,x);

}return map;

}//第四種

public static map count3(string str)

arraylistlist=new arraylist(hset);

int n=hset.size();//有多少種字元

inttimes=new int[n];//儲存每種字元的出現次數

for(char c:cs)

for(int i=0;imap.put(""+list.get(i),times);

}return map;

}//展示

public static void show(mapmap)

}out關鍵字會導致引數通過引用來傳遞。這與ref關鍵字類似,不同之處在於ref要求變數必須在傳遞之前進行初始化。若要使用out引數,方法定義和呼叫方法都必須顯式使用out關鍵字。

例如:classoutexample

staticvoidmain()

}儘管作為out引數傳遞的變數不需要在傳遞之前進行初始化,但需要呼叫方法以便在方法返回之前賦值。

ref和out關鍵字在執行時的處理方式不同,但在編譯時的處理方式相同。因此,如果乙個方法採用ref引數,而另乙個方法採用out引數,則無法過載這兩個方法。例如,從編譯的角度來看,以下**中的兩個方法是完全相同的,因此將不會編譯以下**:

classcs0663_example

publicvoidsamplemethod(refinti)

}但是,如果乙個方法採用ref或out引數,而另乙個方法不採用這兩類引數,則可以進行過載,如下所示:

classrefoutoverloadexample

publicvoidsamplemethod(outinti)}備註

屬性不是變數,因此不能作為out引數傳遞。

2樓:

函式返bai回dustr2在str1中出zhi現dao的次內數容

#include

unsigned int strstrcount( char *str1, char *str2 )

return c;}

3樓:坑爹逗比就是我

#include

#include

int main()

i++;

}printf("%d",count);}

4樓:匿名使用者

#include

#include

void main()

int find(char * a,char * b)return -1;}

5樓:匿名使用者

#include "string.h"

#include "stdio.h"

int strcount(char *,char *);

void main()

int strcount(char *p,char *q)p++;

} return n;}

用c語言編寫乙個程式查詢乙個字串在另乙個字串中出現的次數怎麼寫?

6樓:蛙家居

實現**如下:

#include

#include

int main()

printf("請輸入要篩選的字串:\n");

ch2=getchar();

int j=0;

while(ch2!='\n')

int m,n;//m為s的下標,n為t的下標m=0;

n=0;

int num=0;//num用於記錄選定單詞出現的次數while(m<=i&&n<=j)

else

if(n==j)

}if(m==i+1)

}**二:

int strstr_cnt(const char *string ,const char *substring)

c語言!編寫函式統計子字串在另乙個字串中出現的次數(區分大小寫),字串和子字串都由鍵盤輸入。.

7樓:匿名使用者

#include

#include

int fun(char *a,char *b){   int i,j,n1,n2,n3,n4=0;

n1=strlen(a);

n2=strlen(b);

for(i=0;idun3=0;

for(j=0;j

如圖所zhi示,望採納。。dao。。。。

用c語言在乙個字串中查詢另乙個字串,並統計個數

8樓:凌亂心扉

例如,asdfgasfgasf,as,則輸出3。

#include<stdlib.h>

intmain()

{chars[100],t[20];

charch1,ch2;

printf("請輸入主字串:\n");

ch1=getchar();

inti=0;

while(ch1!='\n')

{s[i]=ch1;

i++;

ch1=getchar();

}printf("請輸入要篩選的字串:\n");

ch2=getchar();

intj=0;

while(ch2!='\n')

{t[j]=ch2;

j++;

ch2=getchar();

}intm,n;//m為s的下標,n為t的下標m=0;

n=0;

intnum=0;//num用於記錄選定單詞出現的次數while(m<=i&&n<=j)

{if(s[m]==t[n])

{m++;

n++;

}else

{m=m-n+1;

n=0;

}if(n==j)

{num++;}}

if(m==i+1)

{printf("出現的次數是%d",num);}}

9樓:硪丨曖戀

參考代bai碼:

#include

int main(void)

printf("子串出現的次數為%d次\n",count);

return 0;}

10樓:匿名使用者

#include

#include

int main(void)

printf("子串出現的次數為%d次\n",count);

return 0;}

c語言:輸入一串字元,再輸入乙個字元,統計該字元在字串中出現的次數,並輸出該字串

11樓:水舞江流

你的程式有許多錯誤,主要有:

1、j沒有初始化為0,直接用作陣列下標是不對的,會導致程式崩潰。而且j沒有+1操作,這樣輸入的字元都會覆蓋到一起。

2、不能既有a[j]=getchar()又有scanf("%c",&a[j]),這樣會導致乙個字元被另乙個覆蓋,陣列不能儲存所有的字元。

3、scanf("%c\n",&m);應寫為scanf("%c",&m);,\n只應出現在printf語句中。

按照你的思路,我把**修改了一下,如下。你可以試試看行不行。

#include

main()

a[j]='\0';

printf("enter a word:");

scanf("%c",&m);

for(j=0;a[j]!='\0';j++)

if(a[j]==m)

count++;

printf("the number is %d\n",count);

return 0;}

12樓:

#include

int main()

a[j]='\0';

printf("enter a word:");

scanf("%c",&m);/*這裡不需要來個\n,不然你輸入的時候也得敲進去\n*/

for(j=0;a[j]!='\0';j++)if(a[j]==m)

count++;

printf("the number is %d\n",count);

return 0;}

13樓:匿名使用者

int count=0,j;

char a[80];

char m;

gets(a);

fflush(stdin);

m=getchar();

for(j=0;a[j];j++)

if(a[j]==m);

count++;

printf("the number is %d\n",count);

c語言程式設計 輸入三行字元,每行字元,要求統計出其中共有

bat炸彈 c語言程式設計 輸入三行字元,每行60個字元,要求統計出其中共有多少個大寫字母 小寫字母 空格 標點符號。include int main void a getchar while a n a getchar while a n printf 大學字母 d 小寫字母 d 數字 d 空格 ...

C語言,求過程,C語言程式,求過程?

程式輸出結果是 a for語句裡迴圈判斷是f s i 即函式返回非0,則迴圈繼續,而f函式是判斷奇偶數,所以陣列裡從0下標開始,是奇數就迴圈,偶數就退出,所以程式輸出是前面3個奇數相加的結果,相加得9,所以選擇a i 0 i 0 等待f s i 返回值 f s 0 a 1 返回a 2,返回值 1 f...

c語言程式題急求答案,C語言程式題 急求答案!!!

黃邦勇帥哥哥 1 b 018a,0 其中 和後面的一個字元為一個字元,因此程式總共有8個字元,也就是 0,1,8,a,0,2 b for a 0,b 1 a b 2 a 2,b 第一次a 0 1 2,第二次a 2 0 2條件成立,第三次a 4而b 1,因此b 2 1條件不成立,所以執行2次迴圈 3 ...