牛客第二期

2023-12-17 11:27:18

#include<bits/stdc++.h>
using namespace std;
class phone{
	// write your code here......
	friend class myphone;
	private:
		int price;
	public:
		phone(int x){
			price=x;
		}
}; 
class myphone{
	private:
		phone a;
	public:
		myphone(int x):a(x){
		}
		int getprice(){
			return a.price;
		}
};
int main(){
	int p;
	cin>>p;
	myphone a(p);
	cout<<a.getprice();
	return 0;
}

#include <iostream>
#include <cstring>
using namespace std;

int main() {

    char str[100] = { 0 };
    cin.getline(str, sizeof(str));

int i=0;
for(i=0;i<100;i++)
{
    if(str[i]=='\0')
    {
        break;
    }
}
cout<<i;
    return 0;
}

#include <iostream>
using namespace std;

int main() {

    char str[30] = { 0 };
    cin.getline(str, sizeof(str));

    int m;
    cin >> m;

    char arr[30] = { 0 };
    char* p = str + m - 1;
    char* q = arr;
    while (*p != '\0')
    {
        *q = *p;
        p++;
        q++;
    }
    cout << arr;

    return 0;
}

#include <iostream>
using namespace std;

void good(int *a,int *b)
{
    int c=*a;
    *a=*b;
    *b=c;
}

int main() {

    int m, n;
    cin >> m;
    cin >> n;

   
    good(&m,&n);

    cout << m << " " << n << endl;

    return 0;
}

#include <iostream>
using namespace std;

int main() {

    int arr[6] = { 0 };
    int* ptr = arr;

    int len = sizeof(arr) / sizeof(int);

    for (int i = 0; i < len; i++) {
        cin >> arr[i];
    }

int i=0;
for(i=0;i<len;i++)
{
    cout<<*(ptr+i)<<" ";
}

    return 0;
}

#include <iostream>
using namespace std;

int main() {
    int a;
    cin >> a;
    int* p = new int[a];
    int q = 0;
    for (q = 0; q < a; q++)
    {
        cin >> *(p + q);
    }
    int count = 0;
    int i = 0;
    for (i = 0; i < a; i++)
    {
        count = count + *(p + i);
    }
    int j = 0;
    printf("%d", count);
    delete[] p;
    return 0;
}

#include <iostream>
using namespace std;
void good(int *p,int a)
{
int i=0;
for(i=0;i<a;i++)
{
    int j=0;
    for(j=0;j<i;j++)
    {
        if(*(p+i)<*(p+j))
        {
            int x;
            x=*(p+i);
            *(p+i)=*(p+j);
            *(p+j)=x;
        }
    }
}
}
int main() {
int a;
cin>>a;
int arr[50];
int i=0;
for(i=0;i<a;i++)
{
    cin>>arr[i];
}
good(arr,a);
int j=0;
for(j=0;j<a;j++)
{
    cout<<arr[j]<<" ";
}

}

文章来源:https://blog.csdn.net/whcwhc111111/article/details/135035565
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。