- 好友
- 1
- 在线时间
- 0 小时
- 最后登录
- 2024-10-27
见习骑士
- UID
- 3209025
- 第纳尔
- 1316
- 精华
- 0
- 互助
- 2
- 荣誉
- 0
- 贡献
- 0
- 魅力
- 20
- 注册时间
- 2020-11-30
鲜花( 3) 鸡蛋( 0)
|
#include <stdlib.h>
#include <string>
#include <vector>
void split_string(std::vector<std::string>& out, const char* in, char delim)
{
while (*in)
{
const char* next = strchr(in, delim);
if (next)
{
std::string tmp(in, next);
out.push_back(tmp);
}
else
{
out.push_back(in);
}
in = (next ? next + 1 : "");
}
}
int main(int argc, char** argv)
{
int div = 3;
if (argc > 1)
{
div = atoi(argv[1]);
}
if (0 == div)
{
return 0;
}
printf("装备防御力变为原来的%d分之一\n",div);
std::vector<std::string> lines;
FILE* fp = fopen("./item_kinds1.txt", "r");
if (NULL != fp)
{
printf("open item_kinds1.txt success!\n");
int line = 0;
char buf[512];
while (!feof(fp))
{
fgets(buf, 512, fp); line++;
std::string tmp(buf);
if (std::string::npos != tmp.find("itm_", 0))
{
std::vector<std::string> vs;
split_string(vs, buf, ' ');
int len = vs.size();
int m1 = atoi(vs[len - 11].c_str());
int m2 = atoi(vs[len - 10].c_str());
int m3 = atoi(vs[len - 9].c_str());
if (m1 > 0 || m2 > 0 || m3 > 0)
{
printf("%s %d %d %d\n", vs[1].c_str(), m1, m2, m3);
}
int nm1 = m1 / 3;
int nm2 = m2 / 3;
int nm3 = m3 / 3;
if (0 == nm1 && m1 > 0)
{
nm1 = 1;
}
if (0 == nm2 && m2 > 0)
{
nm2 = 1;
}
if (0 == nm3 && m3 > 0)
{
nm3 = 1;
}
vs[len - 11] = std::to_string(nm1);
vs[len - 10] = std::to_string(nm2);
vs[len - 9] = std::to_string(nm3);
strcpy(buf, " ");
for (int i = 0; i < vs.size(); i++)
{
strcat(buf, vs[i].c_str());
if ((i + 1) != vs.size())
{
strcat(buf, " ");
}
}
}
lines.push_back(buf);
}
fclose(fp);
}
if (lines.size() > 0)
{
fp = fopen("./item_kinds1_new.txt", "w");
if (NULL != fp)
{
for (int i = 0; i < lines.size(); i++)
{
fprintf(fp, "%s", lines[i].c_str());
}
fclose(fp);
}
printf("create item_kinds1_new.txt file %d lines\n", lines.size());
}
printf("press any key to exit ...");
getchar();
return 0;
}
|
评分
-
查看全部评分
|