博文

不同的单词(2007-04-01 16:03:00)

摘要:同的单词 Time Limit:1s Memory limit:32M Accepted Submit:25 Total Submit:36 给出一个英文单词的列表,计算有多少不同的单词在列表中。 输入数据 本题有多组输入数据,你必须处理到EOF为止 每组数据的第一行有一个整数n, 1<=n<=1000.下面的n行每行一个单词,每个单词的长度不超过20。单词大小写忽略。 输出数据 每组数据输出一个整数,表示不同的单词数。 输入样例5 FZU FzU LOY BNh FZU 输出样例3 Original: FOJ月赛-2007年3月 #include<iostream>#include<cstring>using namespace std; void do_with(char a[]){ int x; for(x=0;x<strlen(a);x++)  if(a[x]>=65&&a[x]<=90)a[x]+=32;}   int main(){ int n,i,j,count; char (*word)[20]; while(scanf("%d",&n)!=EOF) {  count=0;  word=new char[n][20];  for(i=0;i<n;i++)  {   cin>>word[i];   do_with(word[i]);  }  for(i=0;i<n-1;i++)  {   if(strcmp(word[i],"0")==0)continue;   for(j=i+1;j<n;j++)    if(strcmp(word[i],word[j]......

阅读全文(33) | 评论:0

矩形的个数(2007-04-01 15:34:00)

摘要:  矩形的个数 Time Limit:1s Memory limit:32M Accepted Submit:18 Total Submit:38 在一个3*2的矩形中,可以找到6个1*1的矩形,4个2*1的矩形3个1*2的矩形,2个2*2的矩形,2个3*1的矩形和1个3*2的矩形,总共18个矩形。 给出A,B,计算可以从中找到多少个矩形。 输入数据 本题有多组输入数据,你必须处理到EOF为止 输入2个整数A,B(1<=A,B<=1000) 输出数据 输出找到的矩形数。 输入样例1 2 3 2 输出样例3 18 Original: FOJ月赛-2007年3月   #include<stdio.h>int main(){ int a,b,i,j; unsigned  __int64/*long long*/    count=0; while(scanf("%d%d",&a,&b)!=EOF) {         count=0;   for(i=1;i<=a;i++)    for(j=1;j<=b;j++)                 count+=(a+1-i)*(b+1-j);   printf("%I64d \n",count);          /*%lld*/ } return 0;} //注释中表示的是提交程序到Judge时的写法//在vc里定义变量用_int64 ,读入与输出是用%I64d //judge提交是将_int64改成long long ,同时读入与输出改成%lld......

阅读全文(21) | 评论:0

数据溢出处理(2007-04-01 15:29:00)

摘要:6.0用__int64. 8过我们的judge是不支持的。做完改过来再交吧。 就是在vc里定义变量用_int64 ,读入与输出是用%I64d judge提交是将_int64改成long long ,同时读入与输出改成%lld......

阅读全文(40) | 评论:0

*菱形(2007-03-30 12:13:00)

摘要: *菱形 问题描述: 对给定的一个数n输出下列图形。 当n=1 时,输出 .*.*.*.*. 当n=2时,输出 ..*...*.*.*.*.*.*.*...*.. 当n=4时,输出 ....*.......*.*.....*.*.*...*.*.*.*.*.*.*.*.*.*.*.*.*...*.*.*.....*.*.......*.... 输入:       一个数n。(1<=n<=100) 输出:    如图所示。(每行末尾没有多余的空格!)     #include<iostream>using namespace std;int main(){    int n,count=0,flag=0; while(cin>>n) {//处理前n+1行  for(int i=1;i<=n+1;i++)  {   flag=0;   count=0;   for(int j=1;j<=2*n+1;j++)   {    if(j<=n+1-i||count==i){cout<<'.';continue;}    if(flag==1){cout<<'.';flag=0;continue;}    else    {     if(count<i)     {      cout<<'*';      flag=1;     &......

阅读全文(41) | 评论:0

判断浮点数等于0(2007-03-12 16:30:00)

摘要:浮点数不要直接判断等于0,要用fabs(a)<1e-9来判断等于0,浮点数用!号也很不好。......

阅读全文(33) | 评论:0

Power Strings(2007-03-02 22:35:00)

摘要:  Power Strings Time Limit:5s Memory limit:32M Accepted Submit:166 Total Submit:491 Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n). Each test case is a line of input representing s, a string of printable characters. For each s you should print the largest n such that s = a^n for some string a. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case. Sample Inputabcd aaaa ababab . Sample Output1 4 3   #include <stdio.h>#include <string.h> char s[1000001];short next[1000000]; int main(){    int i, j, len;     while (1)    {   ......

阅读全文(34) | 评论:0

阶层和(2007-03-02 21:31:00)

摘要:下面是1!+2!+3!+4!+4!+!+6!……+N!的源代码里面有很大数的阶乘的算法主要是按位算,那么大的数,肯定不能几个字节来存放 #include<stdio.h>              /*注释,对算法可能还表达还不是很完全*/#define N 2500                /*为了方便,把两个空间设为一样大,可以调整,以提高速度。不一定*/long int a[N]={0};           /*运算阶乘的空间*/long int b[N]={0};          /*盛放最后的结果*/long int m;                /*特殊算法产生的中间量,表示进位*/long int g=0;             /*输入的数*/main(){  headprint();           /*调用头输出*/  yunsuan();            /*运算*/  print();      &nb......

阅读全文(49) | 评论:0

变位词(2007-03-02 20:43:00)

摘要:福州大学第三届程序设计竞赛网上赛 变位词 时限:1秒 内存:32M 通过:7 提交:35 Mr. Right有一个奇怪的嗜好,就是看见一个单词就有找它所有的变位词的冲动。一个单词的变位词就是该单词所有字母的一个排列。 输入输出格式 输入数据第一行为一个整数n,1<=n<=10^5,之后n行每行只包含一个单词,不含词组。这些单词构成了Mr. Right的字典。每个单词长度不大于9个字母。接着一行为一个整数m,1<=m<=100,表示Mr. Right将看见的单词数。之后m行每行包含一个单词。(题目中出现的每个单词都只由小写字母组成)对应Mr. Right看到的每个单词,输出落在字典里的它的变位词的个数。 输入样例3 tea ate eat 3 ate abc tea 输出样例3 0 3   #include<iostream>#include<cstring>using namespace std;void ssort(char a[])    //对字符进行排序{ int i,j,l=strlen(a); char c; for(i=0;i<l-1;i++)  for(j=i+1;j<l;j++)   if(a[i]>a[j])   {    c=a[i];    a[i]=a[j];    a[j]=c;   }} int main(){ long n; int m,i,j; char (*cp)[9]; cin>>n; cp=new char[n][9]; for(i=0;i<n;i++) {  cin>>cp[i];  ssort(cp[i]);////对Mr. Right......

阅读全文(150) | 评论:0

动态申请二维数组(2007-03-02 12:34:00)

摘要://申请n个对象数组cp[9][8] int n; float (*cp)[9][8]; cin>>n; cp=new float[n][9][8]; delete []cp;......

阅读全文(38) | 评论:0

Peter's smokes(2007-02-25 11:05:00)

摘要:  Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette. How many cigarettes can Peter have? Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k. For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have. Sample input4 3 10 3 100 5 Output for the sample input5 14 124 Original: Albert 2001   #include<iostream>using namespace std;int main(){    int n,k,num,left; while(cin>>n>>k) {        num=n;  left=n%k;//n butts并制成新烟后剩下的butts.  n/=k;    //用k butts做成新的n根烟  num+=n;  //n根烟抽完又有n butts.  n+=left; //新的n butts加上前面多出来的butts.(下同)        while(n>=k)  {   num+=n/k;   left......

阅读全文(62) | 评论:0