摘要:
1、定义一个静态成员方法,该方法用于提取文件名。比如,给定一个字符串“c:\program files\Maths\all.dat”,使用该方法即可获取文件名all.dat。自行设计程序验证上述方法正确性。 public static string getFilename(stringfile) { //提示:主体中使用string类的indexof方法和substring方法 }代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace sr{ class ... 阅读全文
摘要:
找新朋友Time Limit: 2000/1000 MS(Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s):6928Accepted Submission(s): 3593Problem Description新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。Input第一行是测试数据的组数CN(Casenu 阅读全文
摘要:
/*队空条件:front=rear队满条件:(rear+1)%MaxSize=front进队e操作:rear=(rear+1)%MaxSize; 将e放在rear处出队操作:front=(front+1)%MaxSize;取出front处元素e; */#include #include using namespace std;const int maxn=4;typedef struct{ int data[maxn]; int front,rear;}queue;//初始化队列void init(queue *&q){ q=(queue*)malloc(sizeof(que... 阅读全文
摘要:
代码:#include #include using namespace std;const int maxn=500;typedef struct{ int data[maxn]; int front,rear;}queue;//初始化队列void init(queue *&q){ q=(queue*)malloc(sizeof(queue)); q->rear=q->front=-1;}//销毁队列void destroy(queue *&q){ free(q);}//判断队列是否为空bool empty(queue *&q){ return q-> 阅读全文
摘要:
#include #include using namespace std;typedef struct linknode{ int data; struct linknode *next;}Listack;//初始化栈void init(Listack *&s){ s=(Listack*)malloc(sizeof(Listack)); s->next=NULL;}//摧毁栈void destroy(Listack *&s){ Listack *p=s,*q=s->next; while(q!=NULL) { free(p); ... 阅读全文
摘要:
#include #include using namespace std;const int maxn=500;typedef struct { int data[maxn]; int top;}Stack;//初始化stackvoid init(Stack *&s){ s=(Stack *)malloc(sizeof(Stack)); s->top=-1;}//销毁stackvoid destroy(Stack *&s){ free(s);}//判断栈是否为空bool empty(Stack *s){ return (s->top==-1);}//进stackv 阅读全文
摘要:
吃糖果Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 21695Accepted Submission(s): 6185Problem DescriptionHOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。Input第一行有一个整数T 阅读全文
摘要:
Leonardo's NotebookTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 1791Accepted: 787Description— I just bought Leonardo's secret notebook! Rare object collector Stan Ucker was really agitated but his friend, special investigator Sarah Kepticwas unimpressed.— How do you know it is ge 阅读全文
摘要:
DescriptionWe remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows: This record defines a permutation P as follows: P(1) = 阅读全文
摘要:
方法一:辗转相除法优点:代码简单,容易写。缺点:开销大,用时间多。代码:int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}方法二:二进制算法优点:速度快。主要思想:前提:a>b,分情况讨论:1.a和b均为偶数,gcd(a,b)=2*gcd(a/2,b/2);2.a为偶数b为奇数,gcd(a,b)=gcd(a/2,b);3.a和b均为奇数,gcd(a,b)=gcd(a-b,b)代码:int gcd(int a,int b){ int t=1,c,d; while(a!=b) { if(a>=1; ... 阅读全文