【十二月】第三次课堂练习

P1914

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char s[51];
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++)
    {
        for(int j=1;j<=n;j++)
        {
            s[i]++;
            if(s[i]>'z')
            s[i]='a';
        }
    }
    printf("%s",s);
    return 0;
}
View Code

 P1957

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int len(int a)
{
    int c = a / 10;
    int num = 1;
    while(c != 0)
    {
        c = c / 10;
        num ++;
    }
    return num;
}
void fun(char data1[],char data2[],char symble)
{
    int len1 = strlen(data1);
    int len2 = strlen(data2);
    int sum1 = 0,sum2 = 0;//计算两个字符串代表的数据
    for(int j = 0; j < len1; j ++)
    {
        sum1 = data1[j] - '0' + sum1 * 10;
    }
    for(int j = 0; j < len2; j ++)
    {
        sum2 = data2[j] - '0' + sum2 * 10;
    }
    int sum = 0;
    if(symble == 'a')
    {
        sum = sum1 + sum2;
        printf("%s+%s=%d\n",data1,data2,sum);
        if(sum < 0)
            printf("%d\n",len1 + len2 + 3 + len(sum));
        else
            printf("%d\n",len1 + len2 + 2 + len(sum));
    }
    if(symble == 'b')
    {
        sum = sum1 - sum2;
        printf("%s-%s=%d\n",data1,data2,sum);
        if(sum >= 0)
            printf("%d\n",len1 + len2 + 2 + len(sum));
        else
            printf("%d\n",len1 + len2 + 3 + len(sum));
    }
    if(symble == 'c')
    {
        sum = sum1 * sum2;
        printf("%s*%s=%d\n",data1,data2,sum);
        if(sum >= 0)
            printf("%d\n",len1 + len2 + 2 + len(sum));
        else
            printf("%d\n",len1 + len2 + 3 + len(sum));
    }
}
int main()
{
    char data1[1000];
    char data2[1000];
    char symble;
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i ++)
    {
        scanf("%s",data1);//接受第一个字符串
        if(data1[0] == 'a' || data1[0] == 'b' || data1[0] == 'c')//为三数据输入
        {
            symble = data1[0];
            scanf("%s%s",data1,data2);
            fun(data1,data2,symble);
        }
            else
            {
                scanf("%s",data2);
                fun(data1,data2,symble);
            }
    }
    return 0;
}
View Code

 P5742

#include<iostream>
using namespace std;
int n;
double ok=0;//用来储存综合分数
struct xs{//结构体
    int xh,a1,a2;//xh是学号,a1是学业成绩,a2素质拓展成绩。
}a[1010];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&a[i].xh,&a[i].a1,&a[i].a2);
        ok=a[i].a1*0.7+a[i].a2*0.3;//计算并储存存综合分数
        if(ok>80&&a[i].a1+a[i].a2>140){//判断
            cout<<"Excellent"<<endl;
        }else{
            cout<<"Not excellent"<<endl;
        }
    }
    return 0;
}
View Code

 P5741

#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXN 1000000

int a[MAXN], b[MAXN];

int main() {
    int n, k=0;
    cin >> n;
    string name[n];
    int score[n][4];
    for (int i=0; i<n; ++i) {
        cin >> name[i] >> score[i][0]
            >> score[i][1] >> score[i][2];
        score[i][3] = score[i][0] + score[i][1] + score[i][2];
    }
    for (int i=0; i<n; ++i)
        for (int j=i+1; j<n; ++j)
            if (abs(score[i][0] - score[j][0]) <= 5
                    && abs(score[i][1] - score[j][1]) <= 5
                    && abs(score[i][2] - score[j][2]) <= 5
                    && abs(score[i][3] - score[j][3]) <= 10) {
                a[k] = i;
                b[k++] = j;
            }
    for (int i=0; i<k; ++i)
        cout << name[a[i]] << ' ' << name[b[i]] << endl;
    return 0;
}
View Code

 

posted @ 2021-12-18 09:16  Oranges  阅读(121)  评论(0编辑  收藏  举报