intmain(){ int year,month,day,return_day; scanf("%d",&s_date); s_year=s_date/10000; s_month=s_date/100%100; s_day=s_date%100+1; for (year = s_year; year <= 9999; year++) { if(year!=s_year) s_month=1; for (month = s_month; month <= 12; month++) { if(!(year==s_year && month==s_month)) s_day=1; for (day = s_day; day <= day_num(year,month); day++) { return_day=year*10000+month*100+day; if(flag[0]==0)hw_date(return_day); if(flag[1]==0)AB(return_day); } if(flag[0]==1 && flag[1]==1)break; } if(flag[0]==1 && flag[1]==1)break; } return0; }
第八题(子串分值和)
题目描述
对于一个字符串 S,我们定义 S 的分值 f (S ) 为 S 中出现的不同的字符个数。例如 f (”aba”) = 2, f (”abc”) = 3, f (”aaa”) = 1。 现在给定一个字符串 S [0..n − 1](长度为 n),请你计算对于所有 S 的非空子串 S [i..j] (0<=i<=j<n), f (S [i.. j]) 的和是多少。
输入格式
输入一行包含一个由小写字母组成的字符串S。
输出格式
输出一个整数表示答案。
Input
1
ababc
Output
1
28
样例说明
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
子串 f值 a 1 ab 2 aba 2 abab 2 ababc 3 b 1 ba 2 bab 2 babc 3 a 1 ab 2 abc 3 b 1 bc 2 c 1
intwords_num(char *a,int number){ char *q=a; int num[26]={0},count=0,i; for (; q<a+number; q++) num[*q-'a']=1; for (i=0; i<26; i++) if(num[i]==1) count++; return count; }
intmain(){ int count,sum=0,i,j; scanf("%s",map); for (count=0; map[count]!='\0'; count++); for (i=0; i<count; i++); for (i=0; i<count; i++) for (j=i; j<=count; j++) sum+=words_num(&map[i], j-i); printf("%d",sum); return0; }
第九题(平面切分)
题目描述
平面上有N 条直线,其中第i条直线是 y = Ai · x + Bi。 请计算这些直线将平面分成了几个部分。
输入格式
输入的第一行包含一个整数N。
以下N行,包含两个证书 Ai,Bi。
输出格式
一个整数代表答案
Input
1 2 3 4
3 1 1 2 2 3 3
Output
1
6
Code(未完成)
1 2 3 4
#include<stdio.h> intmain(){ }
第十题(字串排序)
题目描述
小蓝最近学习了一些排序算法,其中冒泡排序让他印象深刻。 在冒泡排序中,每次只能交换相邻的两个元素。小蓝发现,如果对一个字符串中的字符排序,只允许交换相邻的两个字符,则在所有可能的排序方案中,冒泡排序的总交换次数是最少的。 例如,对于字符串 lan 排序,只需要 1 次交换。对于字符串 qiao 排序,总共需要 4 次交换。 小蓝找到了很多字符串试图排序,他恰巧碰到一个字符串,需要 V 次交换,可是他忘了把这个字符串记下来,现在找不到了。 请帮助小蓝找一个只包含小写英文字母且没有字母重复出现的字符串,对该串的字符排序,正好需要 V 次交换。如果可能找到多个,请告诉小蓝最短的那个。如果最短的仍然有多个,请告诉小蓝字典序最小的那个。请注意字符串中可以包含相同的字符。