网易2016两道题Assuming Digits && Best Compression Algorithms

趁热来一发。下面代码没有经过测试,因为其实我没有参加。。。


#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstdint>
#include <sstream>
#include <string>
#include <queue>
#include <limits> 
#include<stack>
using namespace std;

int num[4];
int solve(string a)
{
	memset(num, 0, sizeof(num));
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] == '9')
			num[0]++;
		else if (a[i] == '7')
		{
			if (num[0] > 0)
			{
				num[0]--;
				num[1]++;
			}
		}
		else if (a[i] == '0')
		{
			if (num[1] > 0)
			{
				num[1]--;
				num[2]++;
			}
		}
		else if (a[i] == '6')
		{
			if (num[2] > 0)
			{
				num[2]--;
				num[3]++;
			}
		}
	}
	return num[3];
}
int main()
{
	int n;
	cin >> n;
	string a;
	getchar();
	while (n--)
	{
		getline(cin, a);
		cout << solve(a) << endl;
	}
	
	return 0;
}





#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstdint>
#include <sstream>
#include <string>
#include <queue>
#include <limits> 
#include<stack>
using namespace std;
stack<char> st;
void clear()
{
	while (!st.empty())
		st.pop();
}
bool isDigit(char a)
{
	if (a >= '0' && a <= '9')
		return true;
	return false;
}

int solve(string a)
{
	int mark = 0;
	int count[100];
	memset(count, 0, sizeof(count));
	clear();
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] >= 'A' && a[i] <= 'Z')
		{
			st.push(a[i]);
		}
		else if (isDigit(a[i]))
		{
			int start = i + 1;
			while (start < a.length() && isDigit(a[start]))
				start++;
			string temp = a.substr(i, start - i);
			count[mark] += stoi(temp)+ st.size() - 1;
			i = start - 1;
			clear();
		}
		else if (a[i] == '(')
		{
			count[mark] += st.size();
			mark++;
			clear();
		}
		else if (a[i] == ')')
		{
			count[mark] += st.size();
			clear();

			int sum = count[mark];
			count[mark] = 0;

			int start = i + 1;
			while (start < a.length() && a[start] == ')')
			{
				start++;
				mark--;
				sum += count[mark];
				count[mark] = 0;
			}
			int start2 = start + 1;
			while (start2 < a.length() && isDigit(a[start2]))
				start2++;
			string temp = a.substr(start, start2 - start);
			count[mark] += stoi(temp) * sum;
			i = start2 - 1;
			//mark--;
		}
	} 
	int result = 0;
	for (int i = 0; i < 100; i++)
		result += count[i];
	result += st.size();
	return result;
}

int main()
{
	int n;
	cin >> n;
	string a;
	getchar();
	while (n--)
	{
		getline(cin, a);
		cout << solve(a) << endl;
	}
	return 0;
}


### RTKLIB源码调试中 `.trace` 和 `.stat` 文件的解析 #### 解析 `.trace` 文件 `.trace` 文件记录了RTK定位过程中每一步的关键状态信息,主要用于调试和性能评估。以下是其主要字段及其含义: - **时间戳**:表示观测时刻的时间信息。 - **卫星编号**:参与计算的GNSS卫星PRN号或GnssId[^1]。 - **伪距残差**:用于衡量测量误差大小,通常以米为单位。 - **模糊度浮点解/整数解**:显示当前历元下的浮点解和固定解的状态。 通过读取这些字段可以了解算法运行过程中的细节以及可能存在的问。例如,在实现PPP功能时,可以通过检查`.trace`文件来确认是否成功应用了IGS精密星历数据,并验证不同配置参数的影响效果。 ```python def parse_trace_file(trace_filepath): with open(trace_filepath, 'r') as f: lines = f.readlines() trace_data = [] for line in lines: fields = line.strip().split(',') timestamp = fields[0] satellite_id = int(fields[1]) pseudorange_residual = float(fields[2]) ambiguity_float = float(fields[3]) if len(fields) >= 4 else None ambiguity_fixed = float(fields[4]) if len(fields) >= 5 else None entry = { "timestamp": timestamp, "satellite_id": satellite_id, "pseudorange_residual": pseudorange_residual, "ambiguity_float": ambiguity_float, "ambiguity_fixed": ambiguity_fixed } trace_data.append(entry) return trace_data ``` #### 解析 `.stat` 文件 `.stat` 文件包含了更高级别的统计信息,适合用来分析整体解决方案的质量。它主要包括以下几个部分的信息: - **位置精度指标**:如水平方向和平面方向的标准偏差(STD),反映最终坐标估计值的可靠性程度。 - **收敛时间**:指达到指定精度所需的最短时间间隔。 - **有效卫星数量**:影响定位质量的重要因素之一。 当设置选项 `sopt->sstat>0` 后会触发该类统计数据写入操作。下面给出一段简单的Python脚本示范如何加载并处理此类结构化日志资料。 ```python import numpy as np def parse_stat_file(stat_filepath): stat_data = {'timestamps': [], 'horizontal_std': [], 'vertical_std': []} with open(stat_filepath, 'r') as f: next(f) # Skip header row assuming it exists. for line in f: parts = line.split(',') try: timestamp = parts[0].strip() horizontal_std = float(parts[1].strip()) vertical_std = float(parts[2].strip()) stat_data['timestamps'].append(timestamp) stat_data['horizontal_std'].append(horizontal_std) stat_data['vertical_std'].append(vertical_std) except ValueError: continue return stat_data if __name__ == "__main__": parsed_stats = parse_stat_file('example.stat') avg_horizontal_error = np.mean(parsed_stats['horizontal_std']) max_vertical_deviation = max(parsed_stats['vertical_std']) print(f'Average Horizontal Error: {avg_horizontal_error:.2f} meters.') print(f'Maximum Vertical Deviation: {max_vertical_deviation:.2f} meters.') ``` 上述代码片段展示了基本的数据提取逻辑,实际项目中可根据具体需求调整解析策略。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值