当前位置: 首页 > news >正文

牛客——查找字符串

B-你好,这里是牛客竞赛_牛客周赛 Round 59 (nowcoder.com)

返回值是子串或字符在 string 对象字符串中的位置

#include <bits/stdc++.h>

using namespace std;

int T;
string s;

int main() {
    cin >> T;
    
    while(T --) {
        cin >> s;
        
        if(!s.find("ac.nowcoder.com") || !s.find("https://ac.nowcoder.com"))
            cout << "Ac" << endl;
        else if(!s.find("www.nowcoder.com") || !s.find("https://www.nowcoder.com"))
            cout << "Nowcoder" << endl;
        else cout << "No" << endl;
    }
}

出问题代码
#include<bits/stdc++.h>
#include<cstdio>
#define int long long
using namespace std;#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)const int N = 2e5 + 10;signed main(){IOS;int t;cin >> t;while(t -- ){string s;cin >> s;string a1 = "https://";string b1 = "www.nowcoder";string b2 = "ac.nowcoder";for(int i = 0;i < s.length(); i ++ ) {if(s[i] == 'h') {for(int j =1; j < 8; j ++ ) {if(s[i+j] != a1[j] ) {cout << "No" << endl;break;}}}else if(s[i] == b1[0]) {int flag = 0;for(int j = 1; j < a1.length(); j ++ ) {if(s[i + j] != b1[j] ) {flag = 1;break;}}if(flag == 0) {cout << "Nowcoder" << endl;break;}else {cout << "No" << endl;break;}}else if(s[i] == b2[0]) {int flag = 0;for(int j = 1; j < b2.length(); j ++ ) {if(s[i +j] != b2[j]) {flag = 1;break;}}if(flag == 0) {cout << "Ac"<< endl;break;}else {cout << "No" << endl;break;}}}}return 0;
}
总结:

记住string类中可以查找字符串的方法

学习笔记 c++ (在String查找子串和字符 )-CSDN博客

http://www.lryc.cn/news/434882.html

相关文章:

  • 感恩 各位老师们!和滋养你的人在一起,确实很重要——早读(逆天打工人爬取热门微信文章解读)
  • StorageSync数据缓存API
  • Guitar Pro 8.2.1 Build 32 永久中文破解解锁版
  • 视频编辑SDK解决方案,助力企业快速部署上线
  • 想要从OPPO手机恢复数据?免费OPPO照片视频恢复软件
  • Linux 自主 shell 编写(C 语言实现)
  • pointpillar部署-TensorRT实现(一)
  • ubuntu使用命令行查看硬件信息
  • vue国际化vue-i18n搭配i18n-ally实现多语言国际化
  • Linux(1)--Linux简介
  • Python——破解rar压缩包密码
  • 取指操作流程
  • Git:远程项目代码上传管理
  • MySQL数据库的介绍
  • div内英文不换行问题以及解决方案
  • 『功能项目』DOTween动态文字【26】
  • 经验笔记:框架(Framework)与库(Library)
  • 每日一题——第八十七题
  • CTF——简单的《WEB》
  • 【Nacos】报错之服务实例类型不允许改变
  • SRS流媒体服务器从入门到精通(其一,环境搭建)
  • Java Native Interface (JNI) 简介
  • navigator.mediaDevices.getUserMedia检查用户的摄像头是否可用,虚拟摄像头问题
  • 跨境网红营销SOP流程1.0丨出海笔记
  • Jedis,SpringDataRedis
  • 增量模型的优点例题
  • 求绝对值
  • AlphaNovel的身份验证失败了..........
  • Sapiens:人类视觉模型的基础
  • “健康中国 医路无忧——公益联盟”积极响应,国内首支公益陪诊师志愿队伍正式成立