在猿问上回答了几道题,其中二题还不错,记录一下
题一要求输入一串不是很长的字符串,在最大的字符后加(max),字符串没有空格,只在第一个出现最大的字符后加(max)。
例如
输入 a b z d
输出 a b z(max) d
思路,
1.0 首先把字符串变成字符数组,
2.0 在找出最大字符串位置,
3.0 最后添加(max),把字符数组变成字符串
code
#include#include using namespace std; void display(char ch[],int n); int locate(char ch[],int n); int main() { string str; std::cout << "put into string" << std::endl; cin>>str; //测量字符串数组长度 int len=str.length(); cout<<"leng of string:"< 结果 /home/dfzxk/CLionProjects/untitled3/cmake-build-debug/untitled3 put into string zsdfhyuztryu leng of string:12 z s d f h y u z t r y u 最大位置:0 合并为:z(max)sdfhyuztryu Process finished with exit code 0
题二哪位提问者给的是倒着的。。。。。
code思路,申请二个数组存放奇数数组和偶数数组,主要设计数组动态分配问题
#include#include "stdlib.h" const int N=10; void display(int arr[],int n); int main() { int arr[N]; int i,*p; p=arr; printf("请输入任意10个整数"); for(i=0; i 结果 /home/dfzxk/CLionProjects/untitled1/cmake-build-debug/untitled1 请输入任意10个整数89 45 86 21 33 58 121 100 99 77 89 45 86 21 33 58 121 100 99 77 偶数数组: 86 58 100 奇数数组: 89 45 21 33 121 99 77熟悉慕课,以后到这里玩了。



