2023.1.1

这段代码包括了C++程序,分别处理字符串长度比较决定玩家胜负、根据特定规则判断游戏结果以及替换字符串中特定字符的功能。第一个程序用于比较两个字符串长度并判断玩家1或玩家2获胜,或者平局。第二个程序基于特定字符映射规则决定游戏结果。第三个程序遍历并打印字符串中的每个字符。第四个程序则将字符串中的指定字符替换为#号。
摘要由CSDN通过智能技术生成

 

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
   int n;
   string x,y;
   cin >>n;
   while(n--)
   {
       cin>>x>>y;
       int a=x.size(),b=y.size();
       if (a - b == -1 || a - b == -2 || a - b == 3)

            cout<< "Player1"<<endl;
       else if(a==b)
           cout<< "Tie"<<endl;
       else cout<< "Player2"<<endl;
   }
   return 0;
}
#include <iostream>
#include <string.h>

using namespace std;

int f(string a)
{
    if(a=="Hunter") return 0;
    if(a=="Bear") return 1;
    return 2;
}

int main()
{
    int n;
    cin>>n;
    while(n--){
    string  x,y;
    cin>>x>>y;
    int q=f(x),w=f(y);

    if((q+1)%3==w) cout<<"Player2"<<endl;
    else if(q==w) cout<<"Tie"<<endl;
    else cout<<"Player1"<<endl;
   
    }
   return 0;
}

 

 

#include <iostream>
#include <string.h>

using namespace std;


int main()
{
    string  x;

    getline(cin,x);
    for( char &c: x) //只有对string中的单个字符修改的时候才用&
    cout<<c<<' ';
    return 0;
}
// #include <iostream>
// #include <cstring>
// #include <algorithm>

// using namespace std;

// int main()
// {
//     string a;
//     getline(cin,a);
//     for (int i = 0; i < a.size(); i ++ )
//         cout << a[i] << " ";    //输出元素 + 空格
//     return 0;
// }

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string v;//字符串
      cin>>v;
  char s;//待替换字符
  cin>>s;
  for(auto k:v){//范围 for 循环
        if(k==s) cout << "#";  //是待替换的字符
     else cout <<k;
  }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值