博文
不同的单词(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]......
矩形的个数(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......
数据溢出处理(2007-04-01 15:29:00)
摘要:6.0用__int64. 8过我们的judge是不支持的。做完改过来再交吧。
就是在vc里定义变量用_int64 ,读入与输出是用%I64d judge提交是将_int64改成long long ,同时读入与输出改成%lld......
*菱形(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; &......
判断浮点数等于0(2007-03-12 16:30:00)
摘要:浮点数不要直接判断等于0,要用fabs(a)<1e-9来判断等于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) { ......
变位词(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......
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......
猪的安家(2007-02-22 21:27:00)
摘要: #include <cstdlib> #include <iostream> using namespace std; struct number { int a; int b; }; int main(int argc, char *argv[]) { int num,times,i; number n[10]; cout<<"please input the times Andy built the hogpen(<=10):"; cin>>times; cout<<"please input the numbers of the hogpens(ai) and the remain pigs(bi):"<<endl; for(i=0;i<times;i++) cin>>n[i].a>>n[i].b; i=0;num=n[0].a; while(i<times) { if(n[i].b==num%n[i].a) i++; else{ if(i>0){num+=n[i-1].a;i=0;}else num++; } }
cout<<"the number of pigs is:"<<num<<endl; system("PAUSE"); return EXIT_SUCCESS; }
题目描述:猪的安家这道题目就是要求解模线性方程组。设 n=n1× n2×。。。×nk;m1=n/n1;m2=n/n2;。。。
mk=n/nk;由于mi与ni互质,即可以求解模线性方程。gcd(ni,mi) = ni×x + mi×y=1 求出x和y,y即mi的负一次方;ans = (ans + M * y * A[i]) % n;
#i nclude<string.h>#i nclude<stdio.h>
typedef long long i64;
int num;i64 NN;i64 A[20],N[20];
void ext_euclid( i64 a, i64 b, i64 &x, i64 &y ){ i64 t, d; if (b == 0) { x = 1; y = 0;......
猫捉老鼠(2007-02-22 14:47:00)
摘要:一只猫和一只老鼠在10*10的迷宫中。迷宫中的每个方格可以是空的,或者含有障碍。猫和老鼠可以进入任意一个空的方格中。当他们相遇时,猫和老鼠在同一个方格中。但是,无论猫或老鼠都不能进入有障碍的方格。我们可以用字符组成的二维数组表示迷宫,如下图所示。
老鼠在迷宫中按照一种固定的方式行走:每个时刻,老鼠都向它所面对的方向前进一格,这需要花费1秒时间。如果前方是一个障碍或者是迷宫的边界,它将花1秒的时间按顺时针方向转90度。为了抓到老鼠,这只猫决定也按照与老鼠相同的行走方式行进。猫和老鼠在每个单位时间内是同时行动的。因此,如果猫和老鼠在行进过程中“擦肩而过”,猫是无法捉到老鼠的。只有当猫和老鼠同时到达一个相同的格子时,猫才能捉住老鼠。 初始时,猫和老鼠不会在同一个方格中。并且它们都面向北方。你的任务是编一个程序,求出猫捉到老鼠的所花时间。
输入输出格式
输入数据的第一行n,表示输入数据的组数。每组数据由10行组成,每行10个字符,表示迷宫的地图以及猫和老鼠的初始位置。输入数据保证只有一只猫和一只老鼠。每组输入数据之后均有一个空行作为间隔。 对于每组给定的输入,输出一行仅含一个数,即猫捉到老鼠所花的时间。如果猫永远都无法抓到老鼠,则输出0。
样例输入1
*...*.....
......*...
...*...*..
..........
...*.c....
*.....*...
...*......
..m......*
...*.*....
.*.*......
样例输出49/*C++版*/#include<iostream>using namespace std;struct NODE{ int row; //行 int line;//列};int main(){ char mapx[12][12]; int i,j,k,n,foot,mouse_dir,cat_dir; struct NODE cat,mouse; cin>>n; for(i=0;i<n;i++) { foot=0;//时间(步数)刚开始为0 //以下定义方向......
