1073 Scientific Notation (20 point(s))

本文介绍了一种将科学计数法表示的数转换为常规计数法的方法,特别关注了如何处理非常大的正数和负数,以及如何保持所有有效数字,包括尾部的零。

1073 Scientific Notation (20 point(s))

Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

Input Specification:

Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

Output Specification:

For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.

Sample Input 1:

+1.23400E-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000

找规律、STL字符串处理。

读题关键字:1.数组长度最长9999位(必须字符串处理);2.即使是正数也要给出"+";3.根据样例,指数部分可以有前导0。

思路:1.提取小数部分和指数部分;2.根据指数大于/小于零来分情况处理,其中大于0的话又分成三种情况。

STL string类总结:

1. 初始化和读入

string s;//默认是空串
string s2(s1);//s2初始化为s1的副本
string s(N,'c');//s初始化为N个'c'
string s;cin>>s;//读取字符串,遇到空格的时候结束
string s;getline(cin,s);//读取字符串,空格可读入,直到回车结束
string s;getline(cin,s,'a'); //读取字符串,直到'a'结束,其中任何字符包括回车都能够读入

2. 基本操作

string s="abc";
bool isEmpty = s.empty();    //判断是否为空
int length = s.size();    //字符串长度
int length = s.length();    //同上

3 .添加(append)

string s1="abc";
string s2="123";
s1.append(s2);//在s1的后面添加s2,s1=="abc123"
s1="def";
int pos = 1;
s1.append(s2,pos,s2.length()-pos);//添加s2的pos下标开始剩下的字符,s1=="def23"
s2.append(5,'.');//在s2的后面添加5个".",s2=="123....."

4. 插入(insert)

string s="heo";int pos =2 ,n=2;
s.insert(pos,n,'l');//在字符串s的pos位置插入n个'l' s=="hello" 

s = "ello"; pos = 0;
string s1 = s.insert(pos,"h");//在s的pos位置插入'h' s1=="hello" 

string a = "aa~";pos=0;
string s2 = s1.insert(pos,a);//在s的pos位置插入字符串a s2=="aa~hello" 

5. 翻转、子串

string s="abcd";
reverse(s.begin(),s.end());//翻转字符串,并返回,s=="dcba"
int pos = 1,n=2;
string s1 = s.substr(pos);//s的子串,从pos开始(包括0)到末尾的所有字符的子串,并返回。s1=="cba"
string s2 = s.substr(pos,n);//s的子串,从pos开始(包括0)的n个字符的子串,并返回。s2=="cb"

6. 删除(erase)

string s = "hhhhel~~~looo";
int pos = 11; 
s.erase(pos);//删除s的pos位置的字符,直到结尾 s=="hhhhel~~~lo"
	
pos = 0;int n=3;
s.erase(pos,n); //删除s的pos位置开始的n个字符 s=="hel~~~lo" 
	
string::iterator it;
s.erase(s.begin()+3,s.begin()+6);//删除从first到last中间的字符(first和last都是string类型的迭代器) s=="hello"

7. 替换(replace)

8. 查找(find)

string s="abcdcba";
int pos1 = s.find('b');//查找s中第一次出现b的位置,并返回。pos1==1
int pos2 = s.rfind('b');//查找s中最后一次出现b的位置,并返回。pos2==5
int pos3 = s.find("cd");//使用于字符和字符串 。pos3==2

未完待续... 

#include<iostream>
#include<string>
using namespace std;
int string2int(string s) {//把[+-]003一类的字符串转成数字 
	bool isNeg = false;
	if (s[0] == '-') isNeg = true;
	s.erase(s.begin());
	int ans = 0;
	for (int i = 0; i<s.length(); i++) {
		ans = ans * 10 + s[i] - '0';
	}
	if (isNeg) return -ans;
	else return ans;
}
string moveStr(string s, int offset) {
	if (offset == 0) return s;
	else if (offset > 0) {//x.xxx向右移动
		int fractionLen = s.length() - 2;//小数部分长度 
		s.erase(s.begin() + 1);//去掉小数点 
		if (fractionLen == offset) return s;
		else if (offset > fractionLen) {//移位大于小数部分长度 
			s.append(offset - fractionLen, '0');//末尾补零 
			return s;
		}
		else {//移位小于小数部分长度 
			s=s.insert(offset + 1, ".");//加上小数点
			//bug!!! 写成了fractionLen-offset+1 
			return s;
		}
	}
	else {//x.xxx向左移动 
		s.erase(s.begin() + 1);
		s = s.insert(0, -offset, '0');//前方补零 
		s = s.insert(1, ".");//第一位后面补上小数点 
		return s;
	}
}
int main(void) {
	string s;
	cin >> s;
	if (s[0] == '-') cout << "-";
	s.erase(s.begin());//去除符号位 
	int pos = s.find('E');
	string expStr = s.substr(pos+1, s.length()-pos-1); //获得指数部分字符串,不包括E
	//cout<<expStr<<endl;
	
	s = s.erase(pos, s.length() - pos);//删除指数这个部分
	int exp = string2int(expStr);//获得指数 
	
	//cout<<exp<<endl;
	//cout<<s<<endl;
	cout << moveStr(s, exp) << endl;
	return 0;
}

其它AC代码: 

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    char s[10010];
    scanf("%s",s);
    if(s[0]=='-')
        printf("-");
    int pos=0;
    int len=strlen(s);
        while(s[pos]!='E')
           {
               pos++;
           }
    int exp=0;
    for(int i=pos+2;i<len;i++)
    {
        exp=exp*10+(s[i]-'0');
    }
    if(exp==0)
    {
        for(int i=1;i<pos;i++)
            printf("%c",s[i]);
    }
    if(s[pos+1]=='-')
    {
        printf("0.");
        for(int i=0;i<exp-1;i++)
            printf("0");
        printf("%c",s[1]);
        for(int i=3;i<pos;i++)
            printf("%c",s[i]);
    }
    else
    {
        for(int i=1;i<pos;i++)
        {
            if(s[i]=='.')
                continue;
            printf("%c",s[i]);
            if(i==exp+2&&pos-3!=exp)
                printf(".");
        }
        for(int i=0;i<exp-(pos-3);i++)
            printf("0");
    }
    return 0;
}

 

【CNN-GRU-Attention】基于卷积神经网络和门控循环单元网络结合注意力机制的多变量回归预测研究(Matlab代码实现)内容概要:本文介绍了基于卷积神经网络(CNN)、门控循环单元网络(GRU)与注意力机制(Attention)相结合的多变量回归预测模型研究,重点利用Matlab实现该深度学习模型的构建与仿真。该模型通过CNN提取输入数据的局部特征,利用GRU捕捉时间序列的长期依赖关系,并引入注意力机制增强关键时间步的权重,从而提升多变量时间序列回归预测的精度与鲁棒性。文中涵盖了模型架构设计、训练流程、参数调优及实际案验证,适用于复杂非线性系统的预测任务。; 适合人群:具备一定机器学习与深度学习基础,熟悉Matlab编程环境,从事科研或工程应用的研究生、科研人员及算法工程师,尤其适合关注时间序列预测、能源预测、智能优化等方向的技术人员。; 使用场景及目标:①应用于风电功率预测、负荷预测、交通流量预测等多变量时间序列回归任务;②帮助读者掌握CNN-GRU-Attention混合模型的设计思路与Matlab实现方法;③为学术研究、毕业论文或项目开发提供可复现的代码参考和技术支持。; 阅读建议:建议读者结合Matlab代码逐模块理解模型实现细节,重点关注数据预处理、网络结构搭建与注意力机制的嵌入方式,并通过调整超参数和更换数据集进行实验验证,以深化对模型性能影响因素的理解。
下载前必看:https://pan.quark.cn/s/da7147b0e738 《商品采购管理系统详解》商品采购管理系统是一款依托数据库技术,为中小企业量身定制的高效且易于操作的应用软件。 该系统借助VC++编程语言完成开发,致力于改进采购流程,增强企业管理效能,尤其适合初学者开展学习与实践活动。 在此之后,我们将详细剖析该系统的各项核心功能及其实现机制。 1. **VC++ 开发环境**: VC++是微软公司推出的集成开发平台,支持C++编程,具备卓越的Windows应用程序开发性能。 在该系统中,VC++作为核心编程语言,负责实现用户界面、业务逻辑以及数据处理等关键功能。 2. **数据库基础**: 商品采购管理系统的核心在于数据库管理,常用的如SQL Server或MySQL等数据库系统。 数据库用于保存商品信息、供应商资料、采购订单等核心数据。 借助SQL(结构化查询语言)进行数据的增加、删除、修改和查询操作,确保信息的精确性和即时性。 3. **商品管理**: 系统内含商品信息管理模块,涵盖商品名称、规格、价格、库存等关键字段。 借助界面,用户能够便捷地录入、调整和查询商品信息,实现库存的动态调控。 4. **供应商管理**: 供应商信息在采购环节中占据重要地位,系统提供供应商注册、联系方式记录、信用评价等功能,助力企业构建稳固的供应链体系。 5. **采购订单管理**: 采购订单是采购流程的关键环节,系统支持订单的生成、审批、执行和追踪。 通过自动化处理,减少人为失误,提升工作效率。 6. **报表与分析**: 系统具备数据分析能力,能够生成采购报表、库存报表等,帮助企业掌握采购成本、库存周转率等关键数据,为决策提供支持。 7. **用户界面设计**: 依托VC++的MF...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值