Loading... 矩阵转置 描述 1)输入一个二维数组a[3][4],并且输出矩阵转置前的二维数组。转置后,将转置后的二维数组b[4][3]输出。 2)二维数组的行用i变量表示,二维数组的列j变量表示 输入 无 输出 4*3的矩阵 输入样例 1 1 2 3 4 5 6 7 8 9 1 2 3 输出样例 1 1 5 9 2 6 1 3 7 2 4 8 3 ```C++ #include<iostream> using namespace std; int main() { long long a,b,c,d,e,f,g,h,i,j,k,l; cin>>a>>b>>c>>d; cin>>e>>f>>g>>h; cin>>i>>j>>k>>l; cout<<a<<" "<<e<<" "<<i<<endl; cout<<b<<" "<<f<<" "<<j<<endl; cout<<c<<" "<<g<<" "<<k<<endl; cout<<d<<" "<<h<<" "<<l<<endl; return 0; } ``` 字符串计数 描述 编写函数int StrCount(char * strl,char * str2),其功能是统计字符串str2在strl中出现的次数,返回该数值,要求如下。(10分) 提示:1)在主函数中输入strl和 str2,调用函数StrCount(strl,str2)后输出结果(例如,输入strl为"howareyouareGGGare" ,str2为"are" ,调用函数StrCount后的函数返回值为3,输出结果为3) 输入 字符串1 字符串2 输出 数值 输入样例 1 howareyouareGGGare are 输出样例 1 3 ```C #include <stdio.h> #include <stdlib.h> int StrCount(char* str1,char* str2) { int i,j; int count=0; i=j=0; while(str1[i]!='\0') { while(str1[i]!='\0'&&str2[j]!='\0') { if(str1[i]==str2[j]) { i++; j++; } else { i=i-j+1; j=0; } } if(str2[j]=='\0') { count++; j=0; } } return count; } int main(int argc, char *argv[]) { int count; char str1[10000]; char str2[10000]; scanf("%s %s",str1,str2); count=StrCount(str1,str2); printf("%d",count); return 0; } ``` 最后修改:2023 年 08 月 05 日 © 允许规范转载 赞 1 如果觉得我的文章对你有用,请随意赞赏