srm 144 div 2 550

本文介绍了一种用于解码二进制消息的算法实现。该算法通过遍历输入字符串并利用特定规则来尝试还原原始的二进制编码。文章提供了一个名为`BinaryCode`的类,该类包含一个`decode`方法,可以处理不同类型的输入,并返回可能的解码结果。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>

using namespace std;

class BinaryCode {
public:
	vector <string> decode(string message)
	{
        string p;
        char c;
        int t,i,j=0;
        vector <string> result;
        result.push_back( "NONE" );
        result.push_back( "NONE" );
        message.insert(message.begin(),'0');
        message.insert(message.end(),'0');
        while(j<2)
        {
            p=message;
            p[1]=j+'0';t=0;
            for(i=2;i<message.length()-1;i++)
            {
                p[i]=message[i-1]-p[i-2]-p[i-1]+'0'+'0';
                if(p[i]<'0'||p[i]>'1')
                {t=1;break;}
            }
            if(!t)
            {
                p.erase(0,1);
                p.erase(i-1,1);
                result[j]=p;
                i=message.length()-2;
                c=message[i];
                if(i!=1)
                {
                    if(c!=p[i-1]+p[i-2]-'0')
                    result[j]="NONE";
                }
                else if(c!=p[i-1]) result[j]="NONE";
            }
            j++;
        }
        return result;
	}
};
//<%:start-tests%>
double test0() {
	string p0 = "123210122";
	BinaryCode * obj = new BinaryCode();
	clock_t start = clock();
	vector <string> my_answer = obj->decode(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string t1[] = { "011100011",  "NONE" };
	vector <string> p1(t1, t1+sizeof(t1)/sizeof(string));
	cout <<"Desired answer: " <<endl;
	cout <<"\t{ ";
	if (p1.size() > 0) {
		cout <<"\""<<p1[0]<<"\"";
		for (int i=1; i<p1.size(); i++)
			cout <<", \"" <<p1[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	cout <<endl <<"Your answer: " <<endl;
	cout <<"\t{ ";
	if (my_answer.size() > 0) {
		cout <<"\""<<my_answer[0]<<"\"";
		for (int i=1; i<my_answer.size(); i++)
			cout <<", \"" <<my_answer[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	if (my_answer != p1) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test1() {
	string p0 = "11";
	BinaryCode * obj = new BinaryCode();
	clock_t start = clock();
	vector <string> my_answer = obj->decode(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string t1[] = { "01",  "10" };
	vector <string> p1(t1, t1+sizeof(t1)/sizeof(string));
	cout <<"Desired answer: " <<endl;
	cout <<"\t{ ";
	if (p1.size() > 0) {
		cout <<"\""<<p1[0]<<"\"";
		for (int i=1; i<p1.size(); i++)
			cout <<", \"" <<p1[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	cout <<endl <<"Your answer: " <<endl;
	cout <<"\t{ ";
	if (my_answer.size() > 0) {
		cout <<"\""<<my_answer[0]<<"\"";
		for (int i=1; i<my_answer.size(); i++)
			cout <<", \"" <<my_answer[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	if (my_answer != p1) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test2() {
	string p0 = "22111";
	BinaryCode * obj = new BinaryCode();
	clock_t start = clock();
	vector <string> my_answer = obj->decode(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string t1[] = { "NONE",  "11001" };
	vector <string> p1(t1, t1+sizeof(t1)/sizeof(string));
	cout <<"Desired answer: " <<endl;
	cout <<"\t{ ";
	if (p1.size() > 0) {
		cout <<"\""<<p1[0]<<"\"";
		for (int i=1; i<p1.size(); i++)
			cout <<", \"" <<p1[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	cout <<endl <<"Your answer: " <<endl;
	cout <<"\t{ ";
	if (my_answer.size() > 0) {
		cout <<"\""<<my_answer[0]<<"\"";
		for (int i=1; i<my_answer.size(); i++)
			cout <<", \"" <<my_answer[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	if (my_answer != p1) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test3() {
	string p0 = "123210120";
	BinaryCode * obj = new BinaryCode();
	clock_t start = clock();
	vector <string> my_answer = obj->decode(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string t1[] = { "NONE",  "NONE" };
	vector <string> p1(t1, t1+sizeof(t1)/sizeof(string));
	cout <<"Desired answer: " <<endl;
	cout <<"\t{ ";
	if (p1.size() > 0) {
		cout <<"\""<<p1[0]<<"\"";
		for (int i=1; i<p1.size(); i++)
			cout <<", \"" <<p1[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	cout <<endl <<"Your answer: " <<endl;
	cout <<"\t{ ";
	if (my_answer.size() > 0) {
		cout <<"\""<<my_answer[0]<<"\"";
		for (int i=1; i<my_answer.size(); i++)
			cout <<", \"" <<my_answer[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	if (my_answer != p1) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test4() {
	string p0 = "3";
	BinaryCode * obj = new BinaryCode();
	clock_t start = clock();
	vector <string> my_answer = obj->decode(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string t1[] = { "NONE",  "NONE" };
	vector <string> p1(t1, t1+sizeof(t1)/sizeof(string));
	cout <<"Desired answer: " <<endl;
	cout <<"\t{ ";
	if (p1.size() > 0) {
		cout <<"\""<<p1[0]<<"\"";
		for (int i=1; i<p1.size(); i++)
			cout <<", \"" <<p1[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	cout <<endl <<"Your answer: " <<endl;
	cout <<"\t{ ";
	if (my_answer.size() > 0) {
		cout <<"\""<<my_answer[0]<<"\"";
		for (int i=1; i<my_answer.size(); i++)
			cout <<", \"" <<my_answer[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	if (my_answer != p1) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test5() {
	string p0 = "12221112222221112221111111112221111";
	BinaryCode * obj = new BinaryCode();
	clock_t start = clock();
	vector <string> my_answer = obj->decode(p0);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	string t1[] = { "01101001101101001101001001001101001",  "10110010110110010110010010010110010" };
	vector <string> p1(t1, t1+sizeof(t1)/sizeof(string));
	cout <<"Desired answer: " <<endl;
	cout <<"\t{ ";
	if (p1.size() > 0) {
		cout <<"\""<<p1[0]<<"\"";
		for (int i=1; i<p1.size(); i++)
			cout <<", \"" <<p1[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	cout <<endl <<"Your answer: " <<endl;
	cout <<"\t{ ";
	if (my_answer.size() > 0) {
		cout <<"\""<<my_answer[0]<<"\"";
		for (int i=1; i<my_answer.size(); i++)
			cout <<", \"" <<my_answer[i]<<"\"";
		cout <<" }" <<endl;
	}
	else
		cout <<"}" <<endl;
	if (my_answer != p1) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
//<%:end-tests%>
int main() {
	int time;
	bool errors = false;

	time = test0();
	if (time < 0)
		errors = true;

	time = test1();
	if (time < 0)
		errors = true;

	time = test2();
	if (time < 0)
		errors = true;

	time = test3();
	if (time < 0)
		errors = true;

	time = test4();
	if (time < 0)
		errors = true;

	time = test5();
	if (time < 0)
		errors = true;

	if (!errors)
		cout <<"You're a stud (at least on the example cases)!" <<endl;
	else
		cout <<"Some of the test cases had errors." <<endl;
}



//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!

### 关于 SACMA SRM01 的中文版资料 SACMA SRM01 是由复合材料学会(Society for the Advancement of Material and Process Engineering, SAMPE)发布的标准之一,主要用于描述短切玻璃纤维增强热固性模塑料的性能测试方法[^1]。该标准通常涉及材料特性、制备工艺以及质量控制等方面的内容。 对于寻找 SACMA SRM01 中文版文档的需求,可以通过以下途径获取: #### 1. 官方渠道 SAMPE 或其中国分会可能提供官方翻译版本的下载服务。建议访问 SAMPE China 的官方网站或其他授权机构网站查询是否有正式的中文译本[^2]。 #### 2. 图书馆资源 部分高校图书馆或行业技术中心会收藏此类国际标准的技术文件及其翻译件。可以联系所在地区的科技图书馆或者通过 Interlibrary Loan (ILL) 请求借阅相关文献[^3]。 #### 3. 商业平台购买 一些商业数据库如 CNKI(知网)、万方数据等可能会收录经过合法授权的标准翻译版本。如果这些平台上未找到具体条目,则需进一步确认是否已发布官方认可的中文版本[^4]。 以下是基于 Python 编写的简单脚本来演示如何自动化搜索某些在线学术资源库中的关键词匹配项: ```python import requests from bs4 import BeautifulSoup def search_sacma(keyword="SACMA SRM01"): url = f"https://example-academic-resource.com/search?q={keyword}" response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') results = [] for item in soup.find_all('div', class_='result-item'): title = item.find('h3').text.strip() link = item.find('a')['href'] abstract = item.find('p', class_='abstract').text.strip()[:150]+'...' results.append({ "title": title, "link": link, "abstract": abstract }) return results if __name__ == "__main__": res = search_sacma("SACMA SRM01") for r in res: print(f"{r['title']}\n{r['link']}\nAbstract: {r['abstract']}\n---\n") ``` 请注意以上代码仅为示例用途,在实际应用前应调整目标网址并遵循各站点的服务条款与版权政策[^5]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值