water- Encoding

本文介绍了一种字符串压缩算法,通过统计重复字符并用其出现次数加字符本身表示,从而减少原始字符串长度。每节代码示例清晰,易于理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18521    Accepted Submission(s): 7973


Problem Description
Given a string containing only 'A' - 'Z', we could encode it using the following method: 

1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.

2. If the length of the sub-string is 1, '1' should be ignored.
 

 

Input
The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.
 

 

Output
For each test case, output the encoded string in a line.
 

 

Sample Input
2
ABC
ABBCCC
 

 

Sample Output
ABC
A2B3C
 

**********************************************************************************************************

简单题,统计字母的个数。

View Code
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 char str[10005];
 5 using namespace std;
 6 int main()
 7 {
 8     int n,cnt,len;
 9     char c;
10     scanf("%d",&n);
11     getchar();
12     while(n--)
13     {
14         cnt=1;
15         fgets(str,sizeof(str),stdin);
16         c=str[0];
17         len=strlen(str);
18         for(int i=1;i<=len;i++)
19         {
20             if(c==str[i])
21                 cnt++;
22             else
23             {
24                 if(cnt==1)
25                     printf("%c",str[i-1]);
26                 else
27                     printf("%d%c",cnt,str[i-1]);
28                 c=str[i];
29                 cnt=1;
30             }
31         }
32     }
33     return 0;
34 }

 

 

 

转载于:https://www.cnblogs.com/ubuntu-kevin/archive/2013/01/28/2880649.html

帮我添加一个模型拟合效果图的代码,并且图中需要有回归方程,还有点的图例,此外这个图的横纵坐标要从0开始,让他像sci文章里的回归方程图一样,### 1. 加载包与检查环境 if (!require("mgcv")) install.packages("mgcv") # 确保mgcv包已安装 library(mgcv) ### 2. 数据读取与预处理 # 读取数据(注意文件路径和编码) tryCatch( { data <- read.csv("C:/Users/Administrator/Desktop/08102710001.csv", header = TRUE, fileEncoding = "UTF-8") cat("数据读取成功!\n") }, error = function(e) { stop("文件读取失败,请检查路径或文件名是否为0810.csv") } ) # 检查关键变量是否存在 required_vars <- c("LST_0810", "TEM", "BD", "water", "green", "RD", "JZ", "road_DIST", "NDVI", "water_DIST", "Green_DIST") if (!all(required_vars %in% colnames(data))) { stop("数据列名缺失或与TEM/BD/RD不匹配") } # 删除缺失值(按需替换为插补方法) data_clean <- na.omit(data) cat("删除缺失值后剩余", nrow(data_clean), "条有效数据\n") library(ggplot2) ggplot(data, aes(x=LST_0810)) + geom_histogram(bins=30, fill="skyblue") + theme_bw() ### 3. 构建GAM模型 # 全变量平滑模型(默认自由度) model <- gam( TEM ~ s(LST_0810) + s(BD) + s(road_DIST) + s(water_DIST) + s(NDVI) + s(RD) + s(green) + s(JZ) + s(water) + s(Green_DIST), # 所有自变量施加平滑 data = data_clean, method = "REML", # 推荐参数估计方法 family = gaussian() # 适用于连续型因变量 ) ### 4. 模型诊断与解读 # 模型摘要(关注显著性和解释力) cat("----- 模型摘要 -----\n") print(summary(model)) # 诊断残差与模型假设(需观察图形是否合理) cat("\n----- 模型诊断 -----\n") gam.check(model) ### 5. 可视化效应曲线 # 生成各变量的平滑效应图(含残差) cat("\n----- 效应可视化 -----\n") par(mfrow = c(2, 2)) # 设置2x2画布 plot(model, pages = 1, residuals = TRUE, all.terms = TRUE) par(mfrow = c(1, 1)) # 恢复默认画布
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值