博文
扫雷游戏(2007-02-13 17:11:00)
摘要:扫雷是Windows自带的游戏。游戏的目标是尽快找到雷区中的所有地雷,而不许踩到地雷。如果方块上的是地雷,将输掉游戏。如果方块上出现数字,则表示在其周围的八个方块中共有多少颗地雷。
你的任务是在已知地雷出现位置的情况下,得到各个方块中的数据。 *...
.... “*”表示有地雷
.*.. “.”表示无地雷
....
经过处理应得到 *100
2210
1*10
1110
输入
输入有多组数据,每组数据的第一行有两个数字,m,n(0<m,n<100)表示游戏中雷区的范围为m×n。接下来m行每行有n个字符。“*” 表示有地雷,“.”表示无地雷。最后一组数据m=0,n=0表示输入结束,不需要处理。
输出
对于每组输入数据,输出结果,各方块数字间不留空格。每组结果之后有一个空行。
输入样例2 3
***
...
4 4
*...
....
.*..
....
0 0
输出样例***
232
*100
2210
1*10
1110
Original: FZUPC Warmup 2005
#include<iostream>using namespace std;
void do_with(char n[][100],int a,int b){ int i,j,k,h; for(i=0;i<a;i++) for(j=0;j<b;j++) if(n[i][j]=='*') { for(k=i-1;k<=i+1;k++) for(h=j-1;h<=j+1;h++) if(k<a&&k>=0&&h>=0&&h<b&&n[k][h]!='*')n[k][h]++; }}
int main(){ &nbs......
做减法(2007-02-12 17:55:00)
摘要:乐乐今天刚学减法,老师布置了好多关于减法的家庭作业题。乐乐可不想把时间都浪费在这重复机械的题目上。你能帮帮她吗?
输入输出格式输入数据由多组数据组成。每组数据只有一行,包含两个整数,用空格分开。对于每组数据,输出一行,包含两个整数的差。如果数字超过3位,应从最低位起,按每三位分组。题目所有输入输出保证在[-2^31, 2^31-1]范围内。
样例输入2000 1000
样例输出1,000
Original: FZUPC 2006
#include<iostream>#include<cstring>using namespace std;
void int_to_c(long int a){ long int i,j,k=0,flag=0; char x[20]; if(a<0){a*=-1;flag=-1;} for(i=0;a!=0;i++) {//整数转换为字符串 x[i]=a%10+48; a/=10; } x[i]='\0'; if(flag==-1)cout<<"-"; for(j=i-1,flag=strlen(x)%3;j>=0;j--) { cout<<x[j]; if(flag>0) {//处理对3位取余不为0的情况 flag--; if(flag==0){flag=-1;cout<<",";continue;} } if(flag<=0) {//处理后面位数对3......
HangOver(2007-02-12 15:21:00)
摘要:How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will c......
阅读顺序(2007-02-12 15:19:00)
摘要:大多数语言是从左向右读的。但是,在一些语言中,阅读顺序是从右向左读的。这给语言交流增加了不少的麻烦。现在,请你编写一个程序,能够将一从左到右书写的文字自动转成从右向左的顺序。
输入
输入的第一行是一个数字n(n<100),接下来的有n行的文字,由字母、空格、数字以及各种标点组成,每行文字长度不超过200个字符。
输出
将输入的文字转成从右向左的顺序,一行输入对应一行输出。
输入样例3
a man a plan a canal panama
Frankly, I don't think we'll make much
OK?
输出样例amanap lanac a nalp a nam a
hcum ekam ll'ew kniht t'nod I ,ylknarF
?KO
解释
如果不考虑词与词之间的空格,第一句话从左向右读和从右向左读的结果是一样的:-)
Original: FZUPC Warmup 2005
#include<iostream>#include<cstring>using namespace std;int main(){ char c[100][200]; char str[200]; int n,j,i; cin>>n; cin.getline(str,200); for(i=0;i<n;i++) cin.getline(c[i],200); for(i=0;i<n;i++) { for(j=strlen(c[i])-1;j>=0;j--) cout<<c[i][j]; cout<<endl; } return 0;}......
cin.getline用法(2007-02-12 15:18:00)
摘要:#include<iostream>#include<string>using namespace std;int main(){ int loop; cin>>loop; char n[128]; for(int i=0;i<loop;i++) { cin.getline(n,128); cout<<n; for(int j=strlen(n)-1;j>=0;j--) cout<<n[j]; cout<<endl; } return 0;}
因为cin>>loop没有结束此行的输入,所以cin.getline就只输入了上一行的空白,n==""......
黄易群侠传(2007-01-26 14:02:00)
摘要:通行证用户名:xiaoxiaofeng1987悠游联络码:26827592游戏帐号:HE00036472
原始密码:YCMEF24868
通行证用户名:chendaya悠游联络码:26913786游戏帐号:HE00070010
原始密码:9JKPN3B9GR
通行证用户名:caizhipeng1987 悠游联络码:30069759游戏帐号:HE02581774原始密码:JM8YDHCNK3
轩辕HE00016991201314
采集号:HE00820581123456
HE00509816 157842110 ......
serve people(2006-10-28 20:48:00)
摘要:To serve people, takes dignity and intelligence. But remember, they are just people with money. Although we serve them, we are not their servants. What we do, does not define who we are. What defines us is how well we rise after falling. ......
日期运算(2006-10-06 11:49:00)
摘要:创建一个日期类Date(构造,修改,判断日期非法),然后重载各运算符实现:日期-日期,日期-整数,日期+=整数,日期-=整数日期+整数,整数+日期++日期,日期++,--日期,日期--,重载关系运算符,抽取(输入)运算符>>和插入(输出)运算符<<,最后编写一个主函数对以上功能进行全面测试.
(使用异常处理机制!)
#include<iostream>using namespace std;
//-------------------------------普通函数声明-----------------------------//bool isleapyear(int year); //判断是否为闰年int daysofmonth(int year,int month); //计算年、月对应的天数int days(int year,int month,int day); //计算该日期在本年中是第几天(用于该年为公元后)int ndays(int year,int month,int day); //计算该日距下一年1月1日有多少天(用于该年为公元前)
//前向引用声明class Date;
//-------------------------------友元函数声明-------......
巨型整数运算(2006-10-06 11:43:00)
摘要:
大二上学期程序设计实践课的题目:
编写一个巨型整数类(类名统一规定为:HugeInt),可以用默认值0或长整型数或字符串进行对象的初始化(构造)然后用成员、友元或普通函数等重载相应的运算符实现下述功能(必须优化算法、同时进行异常处理):“巨型整数”OP“巨型整数/长整型数/字符串” [其中OP为:加+、减-、乘*、整除/、求余%、复合运算(+=、-=、*=、/=、%=)和关系运算(>、>=、<、<=、!=和==)]“长整型数/字符串”OP “巨型整数”(其中OP为:+、-、*、/、%和关系运算),求负(-巨型整数),巨型整数++、++巨型整数,--巨型整数、巨型整数--,插入(输出)运算符<<。最后编写一个主函数(测试程序)对以上功能进行全面的测试。必须选Win32 Console Application (控制台应用)实现。
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
本程序为初期完成,有点BUG:如1000位与1000位相乘时速度不快!
待改进,用字符串速度速度很明显加快!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**********备注:(本程序采用的*双端队列*的数据结构构造巨型整数) **********
**************************** ^^__^^构造函数^^__^^ **......
