NOJ——西北工业大学C语言练习(6)

在这里插入图片描述

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
bool cmp(char a,char b)
{
    return a > b;
}
char s[100];
char ans[100];
int main()
{
    scanf("%s", s);
    int n = 0;
    while(1)
    {
        if(s[n] == 0)
            break;
        n++;
    }
    int mid = n / 2;
    if (n % 2 == 0){
        sort(s, s + mid,cmp);
        sort(s + mid, s + n);
        for (int i = 0; i < mid; i++)
        {
            ans[i] = s[i + mid];
            ans[i + mid] = s[i];
        }
    }
    else{
        sort(s, s + mid,cmp);
        sort(s + mid + 1, s + n);
        for (int i = 0; i < mid; i++)
        {
            ans[i] = s[i + mid + 1];
            ans[i + mid + 1] = s[i];
        }
        ans[mid] = s[mid];
    }
    printf("%s", ans);
}

在这里插入图片描述

#include <stdio.h>
#include <string.h>
int main()
{
    char a[10], s[10];
    scanf("%s %s", a, s);
    if (!strcmp(a, "A#"))
        printf("Bb %s", s);
    else if (!strcmp(a, "Bb"))
        printf("A# %s", s);
    else if (!strcmp(a, "C#"))
        printf("Db %s", s);
    else if (!strcmp(a, "Db"))
        printf("C# %s", s);
    else if (!strcmp(a, "D#"))
        printf("Eb %s", s);
    else if (!strcmp(a, "Eb"))
        printf("D# %s", s);
    else if (!strcmp(a, "F#"))
        printf("Gb %s", s);
    else if (!strcmp(a, "Gb"))
        printf("F# %s", s);
    else if (!strcmp(a, "G#"))
        printf("Ab %s", s);
    else if (!strcmp(a, "Ab"))
        printf("G# %s", s);
    else
        printf("unique");
    return 0;
}

在这里插入图片描述

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string s[10];
    for (int i = 0; i < 10;i++)
    {
        cin >> s[i];
    }
    sort(s, s + 10);
    for (int i = 0; i < 10; i++)
    {
        cout << s[i] << " ";
    }
}

在这里插入图片描述

#include <stdio.h>
#include <string.h>
void stringmerge(char s1[],char s2[])
{
    int len1 = strlen(s1);
    int len2 = strlen(s2);
    int i = 0;
    for (i = len1; i <= len1 + len2;++i){
        s1[i] = s2[i - len1];
    }
}
int main()
{
    char s1[100], s2[100];
    scanf("%s %s", s1, s2);
    stringmerge(s1, s2);
    printf("%s", s1);
}

在这里插入图片描述

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
    char s[1000];
    char a[1000];
    char ch;
    int i = 0;
    int j = 0;
    cin.getline(s, 1000);

    for (int i = 0, j = 0; i < strlen(s);i++){
        if(s[i] == 'y' && s[i+1] == 'o' && s[i+2] == 'u'){
            a[j] = 'w';
            a[j + 1] = 'e';
            j += 2;
            i += 2;
        }
        else{
            a[j] = s[i];
            j++;
        }
    }
    printf("%s", a);
}

在这里插入图片描述

#include <stdio.h>
#include <string.h>
int main()
{
    char s[1000];
    scanf("%s", s);
    int up = 0, down = 0;
    for (int i = 0; i < strlen(s);i++)
    {
        if(s[i] == 'S'){
            printf("WA");
            return 0;
        }
        if(s[i] == 'U'){
            up++;
        }
        else{
            down++;
        }
    }
    int a, b, all;
    a = up;
    b = down;
    all = a + b;
    if ((double)up / (double)(up + down) > 0.503 || (double)up / (double)(up + down) < 0.497)
    {
        printf("Fail");
        return 0;
    }
    for (int i = 2; i <= a; i++)
    {
        if (a % i == 0 && all % i == 0)
        {
            a = a / i;
            all = all / i;
        }
    }
    printf("%d/%d", a, all);
}

在这里插入图片描述

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
    map<string, int> m = {
        {"I", 1},
        {"II", 2},
        {"III", 3},
        {"IV", 4},
        {"V", 5},
        {"VI", 6},
        {"VII", 7},
        {"VIII", 8},
        {"IX", 9},
        {"X", 10},
        {"XI", 11},
        {"XII", 12}
    };
    string s;
    cin >> s;
    cout << m[s];
}

在这里插入图片描述

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
    char s1[128] = "", s2[128] = "";
    cin.getline(s1, 128);

    int len = strlen(s1);
    char *p1 = s1 + len - 1; // 字符串尾部指针

    int flag = 0;  // 不是字母
    int count = 0; // 字母个数

    for (int i = 0; i <= len; ++i)
    {
        if (*p1 >= 'a' && *p1 <= 'z' ||
            *p1 >= 'A' && *p1 <= 'Z') // 如果是字母
        {
            count++;  // 记录字母个数
            flag = 1; // 是字母
        }
        else
        {
            flag = 0; // 不是字符
        }

        if (!flag && count) // 出现不是字母且字母个数不为0,进行单词连接
        {
            strncat(s2, p1 + 1, count); // 连接单词
            if (i != len)               // 最后一个单词没有空格
                strcat(s2, " ");

            flag = 1;  // 设定是字母
            count = 0; // 字母个数统计归0
        }
        p1--; // 移动字符串指针
    }

    printf("%s\n", s2); // 有回车

    return 0;
}

在这里插入图片描述

下面的答案是错的,尽管我感觉我写的是对的,但是始终是WA,有知道错在哪的给我说一下

#include <iostream>
#include <cstring>
using namespace std;
int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;
void count(char s[])
{
    for (int i = 0; i < strlen(s); i++)
    {
        if(s[i] >= 'A' && s[i] <= 'Z')
            num1++;
        else if(s[i] >= 'a' && s[i] <= 'z')
            num2++;
        else if(s[i] >= '0' && s[i] <= '9')
            num3++;
        else if(s[i] == ' ')
            num4++;
        else
            num5++;
    }
}
int main()
{
    char s1[1000], s2[1000], s3[1000];
    cin.getline(s1, 1000);
    cin.getline(s2, 1000);
    cin.getline(s3, 1000);
    count(s1);
    count(s2);
    count(s3);
    cout << num1 << " " << num2 << " " << num3 << " " << num4 << " " << num5 ;
}

在这里插入图片描述

#include <stdio.h>
#include <string.h>
int stringcompare(char s1[],char s2[])
{
    for (int i = 0; i < strlen(s1);i++)
    {
        if(s1[i] != s2[i])
        {
            return s1[i] - s2[i];
        }
    }
    return 0;
}
int main()
{
    char s1[100], s2[100];
    scanf("%s%s", s1, s2);
    printf("%d", stringcompare(s1, s2));
}
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alfred young

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值