NOI / 1.7编程基础之字符串 王曙翰

01统计数字字符个数

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    getline(cin,a);
    int count=0;
    for(int i=0;i<a.length();++i)
    {
        if('0'<=a[i]&&a[i]<='9')count++;
    }
    cout<<count;
    return 0;
}

02找第一个只出现一次的字符

#include <bits/stdc++.h>
using namespace std;   
int num[26]={};
int main()
{
    string a;
    cin>>a;
    int flag=1;
    int c=a.length();
    for(int i=0;i<c;++i)
    {  
        num[a[i]-'a']++;
    }
    for(int j=0;j<c;++j)
    {
        if(num[a[j]-'a']==1)
        {
            flag=0;
            printf("%c",a[j]);
            break;
        }
    }
    if(flag)
    {
        cout<<"no";
    }
    return 0;
}

03基因相关性

#include<bits/stdc++.h>
using namespace std;   
int num[26]={};
int main()
{
    double flag;cin>>flag;
    string one;cin>>one;
    string two;cin>>two;
    int len=one.length();
    double same=0;
    for(int i=0;i<len;++i)
    {
        if(one[i]==two[i])same++;
    }
    if((same/len)<flag)
    {
        cout<<"no";
    }
    else
    {
        cout<<"yes";
    }
    return 0;
}

04石头剪子布

#include<iostream>
#include<string>
using namespace std;   
int num[26]={};
int Result(string one,string two)
{
    if((one=="Scissors"&&two=="Paper")||(one=="Paper"&&two=="Rock")||(one=="Rock"&&two=="Scissors"))
    {
        return 1;
    }
    else if(one==two)
    {
        return 0;
    }
    else
    {
        return 2;
    }
     
}
int main()
{
    int n;cin>>n;
    string one;
    string two;
    for(int i=0;i<n;++i)
    {
        cin>>one>>two;
        int c=Result(one,two);
        if(c==1)
        {
            cout<<"Player1\n";
        }
        else if(c==2)
        {
            cout<<"Player2\n";
        }
        else
        {
            cout<<"Tie\n";
        }
    }
    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值