Link:

P1580 传送门

Solution:

拿来练练字符串的读入:

1、$gets()$相当于$c++$中的$getline()$,但返回值为指针!(无数据时为NULL)

(都读入换行符,并将其舍弃)

2、$sscanf(起始指针,.....,......)$可以实现从另一个字符串读入

3、$strcmp$和$memcmp$都是相同时返回值为0

4、$count(begin,end,value)$能实现各个容器中的个数查找

5、$strstr(s1,s2)$能查找$s1$中第一个$s2$的位置,没有子串$s2$时返回$NULL$!

Tips:

1、字符串中的查找函数未找到时返回的是$NULL$

对$NULL$调用会RE,使用前一定要判断

2、这道题数据出的不太好,结束符是一个空格……(不是回车或EOF)

Code:

#include <bits/stdc++.h>

using namespace std;
const int MAXN=;
int cur=;
char text[MAXN],fst[MAXN],n1[MAXN],n2[MAXN]; int main()
{
gets(text);
sscanf(strstr(text,"@"),"@yyy loves %s",fst);
while(++cur)
{
gets(text);
if(strlen(text)==) break; sscanf(text,"yyy loves %s",n1);
if(!strcmp(n1,fst))
return printf("Successful @yyy loves %s attempt",fst),;
//调用指针前要判断
if(strstr(text,"@")!=NULL) sscanf(strstr(text,"@"),"@yyy loves %s",n2);
if(count(text,text+strlen(text),'@')!= || strcmp(n2,fst))
{//注意对count函数的使用
printf("Unsuccessful @yyy loves %s attempt\n",fst);
printf("%d\nyyy loves %s",cur,n1);return ;
}
}
printf("Unsuccessful @yyy loves %s attempt\n",fst);
printf("%d\nGood Queue Shape",cur-);
return ;
}

[P1580] yyy loves Easter_Egg I的更多相关文章

  1. 洛谷 P1580 yyy loves Easter_Egg I

    洛谷 P1580 yyy loves Easter_Egg I 题解: 队列+字符串 #include <cstdio> #include <string> #include ...

  2. [洛谷P1580]yyy loves Easter_Egg I

    题目大意:很多人@一个人,如果那个人忍不住说话了,就轰炸成功,如果那个人没说话或者别的人没有@他或@很多个人,则轰炸失败.(具体见原题) 解题思路:字符串处理,好好用sscanf即可(细节见代码). ...

  3. 题解 洛谷 P1580 【yyy loves Easter_Egg I】

    一言不合上代码: #include<cstdio> #include<cstring> ],bz[],dmz[]; int maohao,xf,ls,sss,lll,xxf,x ...

  4. [洛谷1580]yyy loves Easter_Egg I

    题目背景 Soha的出题效率着实让人大吃一惊.OI,数学,化学的题目都出好了,物理的题还没有一道.于是,Huntfire,absi2011,lanlan对soha进行轮番炸,准备炸到soha出来,不料 ...

  5. yyy loves Easter_Egg I(恶心的字符串模拟)

    题目背景 Soha的出题效率着实让人大吃一惊.OI,数学,化学的题目都出好了,物理的题还没有一道.于是,Huntfire,absi2011,redbag对soha进行轮番炸,准备炸到soha出来,不料 ...

  6. 【洛谷1580】yyy loves Easter_Egg I(字符串处理题)

    点此看题面 大致题意: 略.(一道模拟题,自己去看题面吧) 几个字符数组函数 纯粹是一道字符串处理题,就当是学了一下各种与字符数组相关的函数吧! \(gets()\):这个是比较常用的函数,就是读入一 ...

  7. 洛谷P2397 yyy loves Maths VI (mode)

    P2397 yyy loves Maths VI (mode) 题目背景 自动上次redbag用加法好好的刁难过了yyy同学以后,yyy十分愤怒.他还击给了redbag一题,但是这题他惊讶的发现自己居 ...

  8. P2393 yyy loves Maths II

    P2393 yyy loves Maths IIlong double比如保留5位小数*1000000都变成整数最后再/1000000避免精度误差scanf("%Lf",& ...

  9. 洛谷P2396 yyy loves Maths VII

    P2396 yyy loves Maths VII 题目背景 yyy对某些数字有着情有独钟的喜爱,他叫他们为幸运数字;然而他作死太多,所以把自己讨厌的数字成为"厄运数字" 题目描述 ...

随机推荐

  1. 一个JavaScript日期格式化扩展函数

    我们都知道在Java和PHP语言中,有专门用于格式化日期对象的类和函数,例如Java中的DateFormat等等,通过这些类和函数,我们可以方便的将一个日期对象按照格式的要求输出为字符串,例如对于同一 ...

  2. Faster R-CNN教程

    Faster R-CNN教程 最后更新日期:2016年4月29日 本教程主要基于python版本的faster R-CNN,因为python layer的使用,这个版本会比matlab的版本速度慢10 ...

  3. POJ2396:Budget(带下界的网络流)

    Budget Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8946   Accepted: 3327   Special ...

  4. Step-By-Step: Setting up Active Directory in Windows Server 2016

    There are interesting new features now made available in Windows Server 2016 such as time based grou ...

  5. ORACLE中根据生日得到年龄

    create or replace function F_GETAGE(dateofbirth date) return varchar2 is begin ) then ); else ) then ...

  6. java基础学习(一)hashcode

    hashcode的作用 hashCode()方法是从Object类继承过来的,Object类中的hashCode()方法返回的是对象在内存中地址转换成的int值,如果对象没有重写hashCode()方 ...

  7. BZOJ 3994: [SDOI2015]约数个数和

    3994: [SDOI2015]约数个数和 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 898  Solved: 619[Submit][Statu ...

  8. Nexus 5 Change FireFox OS to android

    1.Enter Fastboot mode,flash recovery: D:\BaiduYunDownload\recovery>fastboot flash recovery 6.0.4. ...

  9. Python 模拟SQL对文件进行增删改查

    #!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__: Dalhhin # Python 3.5.2,Pycharm 2016.3.2 # 2 ...

  10. 基于 Windows 7 的计算机的可用内存可能低于安装内存

    https://support.microsoft.com/zh-cn/kb/978610 症状 在运行 Windows 7 的计算机上,可用内存 (RAM) 可能会低于安装内存. 例如,32 位版本 ...