proj 1007

proj 1007:

DNA Sorting
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 76307 Accepted: 30599

Description

One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence ``DAABEC'', this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence ``AACEDGG'' has only one inversion (E and D)---it is nearly sorted---while the sequence ``ZWQM'' has 6 inversions (it is as unsorted as can be---exactly the reverse of sorted).  

You are responsible for cataloguing a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of ``sortedness'', from ``most sorted'' to ``least sorted''. All the strings are of the same length.  

Input

The first line contains two integers: a positive integer n (0 < n <= 50) giving the length of the strings; and a positive integer m (0 < m <= 100) giving the number of strings. These are followed by m lines, each containing a string of length n.

Output

Output the list of input strings, arranged from ``most sorted'' to ``least sorted''. Since two strings can be equally sorted, then output them according to the orginal order.

Sample Input

10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

Sample Output

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA

Source

 
accepted:
 
#include<iostream>
#include<string>
using namespace std;

int measure(char *s){
	int len = strlen(s);
	int A = 0;
	int C = 0;
	int G = 0;
	int T = 0;
	int value = 0;
	for(int i = len - 1; i >= 0; --i){
		if(s[i] == 'A'){
			++A;
		}
		if(s[i] == 'C'){
			value = value + A;
			++C;
		}
		if(s[i] == 'G'){
			value = value + A + C;
			++G;
		}
		if(s[i] == 'T'){
			value = value + A + C + G;
		}
		//cout<<i<<":"<<value<<endl;
	}
	return value;
}

void special_qsort(int *a, int i, int j, int *b){
	if(i < j){
		int flag = i;
		for(int k = i + 1; k < j + 1; ++k){
			if(a[k] <= a[i]){
				++flag;
				int temp1 = a[k];
				int temp2 = b[k];
				a[k] = a[flag];
				b[k] = b[flag];
				a[flag] = temp1;
				b[flag] = temp2;
			}
		}
		int temp1 = a[i];
		int temp2 = b[i];
		a[i] = a[flag];
		b[i] = b[flag];
		a[flag] = temp1;
		b[flag] = temp2;
		special_qsort(a, i, flag - 1, b);
		special_qsort(a, flag + 1, j, b);
	}
}


int main()
{

	int n,m;
	cin>>n>>m;
	int *b = new int[m];
	for(int i = 0; i < m; ++i){
		b[i] = i;
	}


	char *p = new char[n*m];
	char *p1 = new char[n];
	int *a = new int[m];
	int i = 0;
	while(i < m){
		cin>>p1;
		a[i] = measure(p1);
		for(int j = i*n; j < (i + 1)*n; ++j){
			p[j] = p1[j - i*n];
		}
		++i;
	}
	p[n*m] = '\0';

	special_qsort(a, 0, m - 1, b);
	int t = 0;
	while(t < m){
		for(int j = n*b[t]; j < (b[t] + 1)*n; ++j){
			cout<<p[j];
		}
		cout<<endl;
		++t;
	}
	return 0;
}


Maya Calendar
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 61272 Accepted: 18901

Description

During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day long year, called Haab, which had 19 months. Each of the first 18 months was 20 days long, and the names of the months were pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu. Instead of having names, the days of the months were denoted by numbers starting from 0 to 19. The last month of Haab was called uayet and had 5 days denoted by numbers 0, 1, 2, 3, 4. The Maya believed that this month was unlucky, the court of justice was not in session, the trade stopped, people did not even sweep the floor.  

For religious purposes, the Maya used another calendar in which the year was called Tzolkin (holly year). The year was divided into thirteen periods, each 20 days long. Each day was denoted by a pair consisting of a number and the name of the day. They used 20 names: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers; both in cycles.  

Notice that each day has an unambiguous description. For example, at the beginning of the year the days were described as follows:  

1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, and again in the next period 8 imix, 9 ik, 10 akbal . . .  

Years (both Haab and Tzolkin) were denoted by numbers 0, 1, : : : , where the number 0 was the beginning of the world. Thus, the first day was:  

Haab: 0. pop 0  

Tzolkin: 1 imix 0  
Help professor M. A. Ya and write a program for him to convert the dates from the Haab calendar to the Tzolkin calendar.  

Input

The date in Haab is given in the following format:  
NumberOfTheDay. Month Year  

The first line of the input file contains the number of the input dates in the file. The next n lines contain n dates in the Haab calendar format, each in separate line. The year is smaller then 5000.  

Output

The date in Tzolkin should be in the following format:  
Number NameOfTheDay Year  

The first line of the output file contains the number of the output dates. In the next n lines, there are dates in the Tzolkin calendar format, in the order corresponding to the input dates.  

Sample Input

3
10. zac 0
0. pop 0
10. zac 1995

Sample Output

3
3 chuen 0
1 imix 0
9 cimi 2801

Source



#include<iostream>
#include<string>
#include<string.h>
using namespace std;


bool equal(char *s1, char *s2){
	int i = 0;
	while((s1[i] == s2[i])&& (s1[i] != '\0')){
		++i;
	}
	if((s1[i] == '\0')&& (s2[i] == '\0')){
		return true;
	}else{
		return false;
	}
}

structnode{
	int year;
	int month;
	int day;
	node(int i = 0, int j = 0, int k = 0){
		year = i;
		month = j;
		day = k;
	}
};

int days(int day, char *month, int year){
	char *s[] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"};
	int m = 0;
	while(!equal(month, s[m])){
		++m;
	}
	int days = m*20 + day + 365*year + 1;

	return days;
}

node print(int days){
	int year = days/260;
	int flag = 0;
	if(year*260 == days){
		year = year - 1;
		flag = 1;
	}
	int day;
	int num;
	if(flag){
		day = 19;
		num = 13;
	}else{
		day = ((days - 260*year)%20 - 1);
		num = (days - 260*year)%13;
	}

	if(num == 0){
		num = 13;
	}
	node p;
	p.day  = num;
	p.year = year;
	p.month = day;
	return p;
}

int main(){
	char *s[] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
	int n;
	cin>>n;
	node *pt = new node[n];
	int year;
	string day;
	string month;
	int temp;
	int num;

	for(int k = 0; k < n; ++k){
		cin>>day;
		int m = day.size();
		if(m == 3)temp = 10*(day[0] - '0') + (day[1] - '0');
		if(m == 2)temp = (day[0] - '0');
		cin>>month;
		cin>>year;

		char *p = new char[month.size()];
		for(int i = 0; i < month.size(); ++i){
			p[i] = month[i];
		}
		p[month.size()] = '\0';
		pt[k] = print(days(temp,p,year));
	}
    cout<<n<<endl;
	for(int i = 0; i < n; ++i){
		cout<<pt[i].day<<" "<<s[pt[i].month]<<" "<<pt[i].year<<endl;
	}
	return 0;
}

转载于:https://www.cnblogs.com/candycloud/p/3390910.html

在调试CANFESTIVAL协议栈之时,已知 typedef struct struct_CO_Data CO_Data; /* A macro to initialize the data in client app.*/ /* CO_Data structure */ #define CANOPEN_NODE_DATA_INITIALIZER(NODE_PREFIX) {\ /* Object dictionary*/\ & NODE_PREFIX ## _bDeviceNodeId, /* bDeviceNodeId */\ NODE_PREFIX ## _objdict, /* objdict */\ NODE_PREFIX ## _PDO_status, /* PDO_status */\ NULL, /* RxPDO_EventTimers */\ _RxPDO_EventTimers_Handler, /* RxPDO_EventTimers_Handler */\ & NODE_PREFIX ## _firstIndex, /* firstIndex */\ & NODE_PREFIX ## _lastIndex, /* lastIndex */\ & NODE_PREFIX ## _ObjdictSize, /* ObjdictSize */\ & NODE_PREFIX ## _iam_a_slave, /* iam_a_slave */\ NODE_PREFIX ## _valueRangeTest, /* valueRangeTest */\ \ /* SDO, structure s_transfer */\ {\ REPEAT_SDO_MAX_SIMULTANEOUS_TRANSFERS_TIMES(s_transfer_Initializer)\ },\ \ /* State machine*/\ Unknown_state, /* nodeState */\ /* structure s_state_communication */\ {\ 0, /* csBoot_Up */\ 0, /* csSDO */\ 0, /* csEmergency */\ 0, /* csSYNC */\ 0, /* csHeartbeat */\ 0, /* csPDO */\ 0 /* csLSS */\ },\ _initialisation, /* initialisation */\ _preOperational, /* preOperational */\ _operational, /* operational */\ _stopped, /* stopped */\ NULL, /* NMT node reset callback */\ NULL, /* NMT communications reset callback */\ \ /* NMT-heartbeat */\ & NODE_PREFIX ## _highestSubIndex_obj1016, /* ConsumerHeartbeatCount */\ NODE_PREFIX ## _obj1016, /* ConsumerHeartbeatEntries */\ NODE_PREFIX ## _heartBeatTimers, /* ConsumerHeartBeatTimers */\ & NODE_PREFIX ## _obj1017, /* ProducerHeartBeatTime */\ TIMER_NONE, /* ProducerHeartBeatTimer */\ _heartbeatError, /* heartbeatError */\ \ {REPEAT_NMT_MAX_NODE_ID_TIMES(NMTable_Initializer)},\ /* is well initialized at "Unknown_state". Is it ok ? (FD)*/\ \ /* NMT-nodeguarding */\ TIMER_NONE, /* GuardTimeTimer */\ TIMER_NONE, /* LifeTimeTimer */\ _nodeguardError, /* nodeguardError */\ & NODE_PREFIX ## _obj100C, /* GuardTime */\ & NODE_PREFIX ## _obj100D, /* LifeTimeFactor */\ {REPEAT_NMT_MAX_NODE_ID_TIMES(nodeGuardStatus_Initializer)},\ \ /* SYNC */\ TIMER_NONE, /* syncTimer */\ & NODE_PREFIX ## _obj1005, /* COB_ID_Sync */\ & NODE_PREFIX ## _obj1006, /* Sync_Cycle_Period */\ /*& NODE_PREFIX ## _obj1007, */ /* Sync_window_length */\ _post_sync, /* post_sync */\ _post_TPDO, /* post_TPDO */\ _post_SlaveBootup, /* post_SlaveBootup */\ _post_SlaveStateChange, /* post_SlaveStateChange */\ \ /* General */\ 0, /* toggle */\ NULL, /* canSend */\ NODE_PREFIX ## _scanIndexOD, /* scanIndexOD */\ _storeODSubIndex, /* storeODSubIndex */\ /* DCF concise */\ NULL, /*dcf_odentry*/\ NULL, /*dcf_cursor*/\ 1, /*dcf_entries_count*/\ 0, /* dcf_status*/\ 0, /* dcf_size */\ NULL, /* dcf_data */\ \ /* EMCY */\ Error_free, /* error_state */\ sizeof(NODE_PREFIX ## _obj1003) / sizeof(NODE_PREFIX ## _obj1003[0]), /* error_history_size */\ & NODE_PREFIX ## _highestSubIndex_obj1003, /* error_number */\ & NODE_PREFIX ## _obj1003[0], /* error_first_element */\ & NODE_PREFIX ## _obj1001, /* error_register */\ & NODE_PREFIX ## _obj1014, /* error_cobid */\ /* error_data: structure s_errors */\ {\ REPEAT_EMCY_MAX_ERRORS_TIMES(ERROR_DATA_INITIALIZER)\ },\ _post_emcy, /* post_emcy */\ /* LSS */\ lss_Initializer\ } 定义了:CO_Data TestSlave_Data = CANOPEN_NODE_DATA_INITIALIZER(TestSlave); 通过IAR编译的时候,发现 Error[Pe144]: a value of type "indextable const *(*)(CO_Data *, unsigned short, unsigned long *, ODCallback_t **)" cannot be used to initialize an entity of type "scanIndexOD_t" (aka "indextable const *(*)(CO_Data *, unsigned short, unsigned long *)") D:\ruanjian\n2l\RZN2Ldemo+shuomingshu\Example-program-package\RZN2L_RSK_canfd_Rev200\iccarm\RZN2L_RSK_canfd_Rev200a\CanFestival\driver\TestSlave.c 635 补充:TestSlave只找到了#include "TestSlave.h" 请问该如何解决报错Error[Pe144]。
06-07
(1)普通用户端(全平台) 音乐播放核心体验: 个性化首页:基于 “听歌历史 + 收藏偏好” 展示 “推荐歌单(每日 30 首)、新歌速递、相似曲风推荐”,支持按 “场景(通勤 / 学习 / 运动)” 切换推荐维度。 播放页功能:支持 “无损音质切换、倍速播放(0.5x-2.0x)、定时关闭、歌词逐句滚动”,提供 “沉浸式全屏模式”(隐藏冗余控件,突出歌词与专辑封面)。 多端同步:自动同步 “播放进度、收藏列表、歌单” 至所有登录设备(如手机暂停后,电脑端打开可继续播放)。 音乐发现与管理: 智能搜索:支持 “歌曲名 / 歌手 / 歌词片段” 搜索,提供 “模糊匹配(如输入‘晴天’联想‘周杰伦 - 晴天’)、热门搜索词推荐”,结果按 “热度 / 匹配度” 排序。 歌单管理:创建 “公开 / 私有 / 加密” 歌单,支持 “批量添加歌曲、拖拽排序、一键分享到社交平台”,系统自动生成 “歌单封面(基于歌曲风格配色)”。 音乐分类浏览:按 “曲风(流行 / 摇滚 / 古典)、语言(国语 / 英语 / 日语)、年代(80 后经典 / 2023 新歌)” 分层浏览,每个分类页展示 “TOP50 榜单”。 社交互动功能: 动态广场:查看 “关注的用户 / 音乐人发布的动态(如‘分享新歌感受’)、好友正在听的歌曲”,支持 “点赞 / 评论 / 转发”,可直接点击动态中的歌曲播放。 听歌排行:个人页展示 “本周听歌 TOP10、累计听歌时长”,平台定期生成 “全球 / 好友榜”(如 “好友中你本周听歌时长排名第 3”)。 音乐圈:加入 “特定曲风圈子(如‘古典音乐爱好者’)”,参与 “话题讨论(如‘你心中最经典的钢琴曲’)、线上歌单共创”。 (2)音乐人端(创作者中心) 作品管理: 音乐上传:支持 “无损音频(FLAC/WAV)+ 歌词文件(LRC)+ 专辑封面” 上传,填写 “歌曲信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值