1006 Sign In and Sign Out

该文章描述了一个C++程序,用于处理一组签到和签退时间,通过比较找出最早签到和最晚签退的时间。程序使用sscanf进行字符串到整数的转换并进行时间比较。在VS环境下需使用sscanf_s,但提交时需改为sscanf。程序遍历所有成员的时间记录,更新最早和最晚时间。
摘要由CSDN通过智能技术生成

1006 Sign In and Sign Out

题目大意

选出一个最早的时间,和一个最晚的时间

算法思想

  • 处理时间的时候比较麻烦,用的sscanf才能将string换成int比较
  • vs编译的时候好像只能sscanf_s才能编译通过,但是提交时,比较改成sscanf才能编译
  • 没什么特殊点,写出来就满分

代码

#include<iostream>
#include<string>
#include<vector>
using namespace std;
bool compare(string s, string p)//比较时间函数
{
	int hour1, min1, sec1;
	int hour2, min2, sec2;
	sscanf(s.c_str(), "%d:%d:%d", &hour1, &min1, &sec1);//我用vs就得换成sscanf_s才行,但是提交时会编译出错,必须换成sscanf才能提交
	sscanf(p.c_str(), "%d:%d:%d", &hour2, &min2, &sec2);
	if (hour1 < hour2)//依次比较时分秒
		return true;
	else if (hour1 > hour2)
		return false;
	else
	{
		if (min1 < min2)
			return true;
		else if (min1 > min2)
			return false;
		else
		{
			if (sec1 < sec2)
				return true;
			else if (sec1 > sec2)
				return false;
			else
				return false;
		}
	}
}
int main()
{
	int n;
	int i,j;
	string ear, las;
	string eaid, laid;
	cin >> n;
	vector<vector<string>>time(n);
	for (i = 0; i < n; i++)//输入n个成员
	{
		string a, b, c;
		cin >> a >> b >> c;
		time[i].push_back(a);
		time[i].push_back(b);
		time[i].push_back(c);
	}
	ear = time[0][1];//先选出一个最早和最晚
	eaid = time[0][0];
	las = time[0][2];
	laid = time[0][0];
	for (i = 1; i < n; i++)
	{
		if (!compare(ear, time[i][1]))//比较谁更小,所以要加!
		{
			ear=time[i][1];
			eaid = time[i][0];
		}
		if (compare(las, time[i][2]))//选出谁更大
		{
			las = time[i][2];
			laid = time[i][0];
		}
	}
	cout << eaid << " " << laid;
	return 0;
}
"Place sign in" 错误通常出现在使用 Spring Security 进行身份验证的应用程序中。这通常意味着用户没有通过身份验证并且没有正确的会话信息。可能的原因是在使用 HttpSession 时,没有正确地配置 Spring Security。 为了解决这个问题,你可以尝试以下步骤: 1. 确保在 Spring Security 配置中启用了会话管理: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.ALWAYS); } } ``` 2. 确保使用 Spring Security 进行身份验证时,正确地配置了 HttpSession: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.ALWAYS) .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout() .logoutSuccessUrl("/") .permitAll() .and() .authorizeRequests() .antMatchers("/admin/**").hasRole("ADMIN") .anyRequest().authenticated(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user").password("password").roles("USER") .and() .withUser("admin").password("password").roles("USER", "ADMIN"); } } ``` 3. 确保在使用 HttpSession 时,正确地配置了 Spring Boot 的属性: ```properties # application.properties server.servlet.session.timeout=30m ``` 如果你仍然遇到问题,可能需要进一步检查你的代码和配置是否正确。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值