首页 > 其他分享 >洛谷P1580 yyy loves Easter_Egg I

洛谷P1580 yyy loves Easter_Egg I

时间:2024-03-03 22:35:49浏览次数:17  
标签:洛谷 yyy everything loves Maths include Egg define

洛谷P1580 yyy loves Easter_Egg I

洛谷传送门

调试的有点惨痛的简单字符串模拟题目

Code

/**************************************************************
 * Problem: 
 * Author: Vanilla_chan
 * Date: 
 * E-Mail: [email protected]
 **************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<limits.h>
#define IL inline
#define re register
#define LL long long
#define ULL unsigned long long
#ifdef TH
#define debug printf("Now is %d\n",__LINE__);
#else
#define debug
#endif
#ifdef ONLINE_JUDGE
char buf[1<<23],* p1=buf,* p2=buf,obuf[1<<23],* O=obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#endif
using namespace std;



#define N 5


int cnt_at(string s)
{
	int ans=0;for(int i=0;i<s.size();i++) if(s[i]=='@') ans++;
	return ans;
}
string str;
pair<string,string>last,now;
int cnt;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
	
	while(getline(cin,str))
	{
		if(str==""||str=="\r") break;
		++cnt;
		int maohao=str.find(':');
		now.first=str.substr(0,maohao-1);
		//cout<<now.first<<'\n';
		if(cnt!=1&&now.first==last.second)
		{
			cout<<"Successful @"<<now.first<<" attempt"<<'\n';
			return 0;
		}
		
		if(str.find('@')!=string::npos)
		{
			int at=str.find('@');
			int tail=str.find(' ',at+11);//@yyy loves
			if(str.find(' ',at+11)==string::npos) now.second=str.substr(at+1);
			else now.second=str.substr(at+1,tail-at-1);
			if(now.second.back()=='\r') now.second.pop_back();
			//cout<<now.second<<'\n';
		}
			
		
		
		if(cnt!=1&&(str.find('@')==string::npos||cnt_at(str)>=2||now.second!=last.second))
		{
			debug
			cout<<"Unsuccessful @"<<last.second<<" attempt"<<'\n';
			cout<<cnt<<'\n';
			cout<<now.first<<'\n';
			return 0;
		}
		
		
		
		last=now;
	}
	
	
	cout<<"Unsuccessful @"<<last.second<<" attempt"<<'\n';
	cout<<cnt<<'\n';
	
	
	
	cout<<"Good Queue Shape"<<'\n';
	
	
	return 0;
}

测试点的奇怪组合

这里给遇到了以下问题的同学一点帮助

#2,#7,#10

由于linux下getline是遇到\n才停止,而这测试点的数据是在windows下造的,所以就会把\r读取到这行的末尾。如果恰恰好@yyy loves xxx又是在一行的末尾的话,就会导致变成@yyy loves xxx\r。你需要特判一行的末尾是否为\r,并将其pop_back()

#6

注意到题目末尾有这样一句话:

  • 并不保证后面说话的艾特了几个人 然而艾特人数不为一个人视为破坏队形;

需要先看看@的数量,多了少了都不行

#5,#8,#9

还是getline的问题。如果最后用空行来判断是否结束的话,由于会认为\r是一行中的一个字符而不是换行符,所以多出来的空行都被读取了,导致答案多了很多。

几个测试点数据

#2

2.in

yyy loves CH3(CH2)6COOH : @yyy loves everything
yyy loves anything : @yyy loves everything are you calling me?
yyy loves CH3(CH2)6COOH : @yyy loves everything no. I'm calling yyy loves yyy.
yyy loves yyy : hey. @yyy loves everything
yyy loves Maths : what are you doing ? @yyy loves .... are you calling everything?
yyy loves anything : queue_shape breaker
yyy loves yyy : queue_shape breaker
yyy loves CH3(CH2)6COOH : queue_shape breaker
yyy loves everything : queue_shape breaker
yyy loves _o_r_z_y_y_y_2_0_1_5_c_0_1_!_ : queue_shape breaker

2.out

Unsuccessful @yyy loves everything attempt
5
yyy loves Maths

#5

P1580_5.7z

#6

6.in

yyy loves OI : @yyy loves Maths wo pei fu ni de chu ti xiao lv
yyy loves Chemistry : @yyy loves Maths hai bu qu xie std!
yyy loves Microelectronic : +1 @yyy loves Maths
yyy loves TJK : @yyy loves Maths kuai chu lai xie daima
yyy loves kkk : +2 @yyy loves Maths ni shi bu shi si la @yyy loves Maths 
yyy loves Maths : wo lai le   @yyy loves Maths 

6.out

Unsuccessful @yyy loves Maths attempt
5
yyy loves kkk

标签:洛谷,yyy,everything,loves,Maths,include,Egg,define
From: https://www.cnblogs.com/Vanilla-chan/p/18050889

相关文章

  • 洛谷题单指南-二分查找与二分答案-P1163 银行贷款
    原题链接:https://www.luogu.com.cn/problem/P1163题意解读:利率越小,贷款期限和每个月还的钱固定的情况下,越有可能能够还完全部的贷款,具备单调性,因此给定贷款利率、贷款月数、每月还款钱数,可以计算最终贷款还剩下多少,有两种情况:>=0,说明利率可能大了,要试探更小利率;<0,说明利率小了,要......
  • 「杂题乱刷」洛谷 P4801
    链接套路题。最小值:排序后直接分讨即可。最大值:排序后枚举开头为\(a_1\),\(a_n\)的情况后双指针贪心即可。代码:点击查看代码/*Tips:你数组开小了吗?你MLE了吗?你觉得是贪心,是不是该想想dp?一个小时没调出来,是不是该考虑换题?*/#include<bits/stdc++.h>usingnamespa......
  • 【洛谷】阶乘之和(高精度运算)
    题目描述看起来很简单,但是n的取值范围是<=50,结果有可能会很大,一般的算法AC不了。题解上说要用一种叫做高精度运算的算法:24.cnblogs.com/blog/3213233/202403/3213233-20240302211217307-1826622717.png)这里的高精度算法可想而知一定不是能用long数据类型就能解决的问题。......
  • 洛谷题单指南-二分查找与二分答案-P1182 数列分段 Section II
    原题链接:https://www.luogu.com.cn/problem/P1182题意解读:每段和的最大值越小,则分段数就越多,因此可以通过给定每段和的最大值,将分段数划分为两类:<=M,>M,对每段和的最大值进行二分即可。解题思路:二分的判定条件为,给定每段和的最大值,计算分段数,计算逻辑如下:依次遍历每一个数,求当前......
  • 【洛谷】数的性质
    题目不难,但是很考验读题的能力和运用逻辑符号的能力。代码:#include<iostream>usingnamespacestd;intmain(){ intx; cin>>x; boolres[4]={0,0,0,0}; boola=(x%2==0); boolb=(x>4&&x<=12); if(a&&b){ res[0]=1; } if(a||b){ ......
  • 【洛谷】虫子吃苹果
    看似很简单,但是这种现实情境的问题特别需要处理特殊情况,如不能出现剩余苹果为负数的情况等等。看到现实问题类型的题目都要想到这些问题。官方题解代码:#include<bits/stdc++.h>//万能头文件usingnamespacestd;intm,t,s;intmain(){ cin>>m>>t>>s; if(t==0)//特判t=0的......
  • 洛谷题单指南-二分查找与二分答案-P3853 [TJOI2007] 路标设置
    原题链接:https://www.luogu.com.cn/problem/P3853题意解读:相邻路标的最大距离即空旷指数,空旷指数越小,用的路标越多,因此可以根据空旷指数将使用路标情况分成两类:路标数<=K,路标数>K,对空旷指数进行二分即可。解题思路:二分的判定条件为,给定空旷指数,计算需要的路标数只需遍历每两......
  • 洛谷题单指南-二分查找与二分答案-P2678 [NOIP2015 提高组] 跳石头
    原题链接:https://www.luogu.com.cn/problem/P2678题意解读:最短跳跃距离越大,要移走的石头就越多,因此可以根据最短跳跃距离的不同把情况分为两类:移走的石头数<=M、移走的石头数>M,对最短跳跃距离二分即可。解题思路:二分的判定条件如下:对于给定最短跳跃距离,需要计算移走的石头数,......
  • 洛谷题单指南-二分查找与二分答案-P2440 木材加工
    原题链接:https://www.luogu.com.cn/problem/P2440题意解读:切出来的长度越短,则段数越多,可以通过二分长度来解决。解题思路:二分的关键在于判定条件,此题就是对二分到的长度计算可以切割的段数,如果段数大于等于k,则满足要求,可以继续加大长度。注意点:1、计算切割出来的段数是累加:每......
  • 洛谷题单指南-二分查找与二分答案-P1678 烦恼的高考志愿
    原题链接:https://www.luogu.com.cn/problem/P1678题意解读:要计算不满意度之和的最小值,就要保证每个人的不满意度最小,即选择的学校录取分数-学生分数之差的绝对值最小。解题思路:如何在学校录取分数中找与学生分数最接近的呢?有三种可能:1、学生分数在录取分数中存在相等的2、学......