mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-03 00:23:15 +08:00
remove problem text and trim tailing spaces.
This commit is contained in:
+3
-27
@@ -1,27 +1,3 @@
|
||||
/**
|
||||
* 1001. A+B Format (20)
|
||||
*
|
||||
* Calculate a + b and output the sum in standard format -- that is, the digits
|
||||
* must be separated into groups of three by commas (unless there are less than
|
||||
* four digits).
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. Each case contains a pair of integers
|
||||
* a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a
|
||||
* space.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each test case, you should output the sum of a and b in one line. The sum
|
||||
* must be written in the standard format.
|
||||
*
|
||||
* Sample Input
|
||||
* -1000000 9
|
||||
* Sample Output
|
||||
* -999,991
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -29,16 +5,16 @@ int main()
|
||||
{
|
||||
int a, b, pos;
|
||||
char num[11];
|
||||
|
||||
|
||||
scanf("%d%d", &a, &b);
|
||||
sprintf(num, "%d", a + b);
|
||||
|
||||
|
||||
for(pos = strlen(num) - 3; pos > 0 && num[pos - 1] != '-'; pos -= 3)
|
||||
{
|
||||
memmove(num + pos + 1, num + pos, strlen(num) - pos + 1);
|
||||
num[pos] = ',';
|
||||
}
|
||||
|
||||
|
||||
puts(num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+9
-35
@@ -1,29 +1,3 @@
|
||||
/**
|
||||
* 1002. A+B for Polynomials (25)
|
||||
*
|
||||
* This time, you are supposed to find A+B where A and B are two polynomials.
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. Each case occupies 2 lines, and each
|
||||
* line contains the information of a polynomial: K N1 a_N1 N2 a_N2 ... NK a_NK,
|
||||
* where K is the number of nonzero terms in the polynomial, Ni and a_Ni (i=1,
|
||||
* 2, ..., K) are the exponents and coefficients, respectively. It is given that
|
||||
* 1 <= K <= 10,0 <= NK < ... < N2 < N1 <=1000.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each test case you should output the sum of A and B in one line, with the
|
||||
* same format as the input. Notice that there must be NO extra space at the end
|
||||
* of each line. Please be accurate to 1 decimal place.
|
||||
*
|
||||
* Sample Input
|
||||
* 2 1 2.4 0 3.2
|
||||
* 2 2 1.5 1 0.5
|
||||
* Sample Output
|
||||
* 3 2 1.5 1 2.9 0 3.2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
@@ -36,15 +10,15 @@ int main()
|
||||
{
|
||||
int KA, KB, Ksum = 0;
|
||||
Poly A, B, sum;
|
||||
|
||||
|
||||
scanf("%d", &KA);
|
||||
for(int i = 0; i < KA; i++)
|
||||
for(int i = 0; i < KA; i++)
|
||||
scanf("%d %lf", &A[i].exp, &A[i].coef);
|
||||
|
||||
|
||||
scanf("%d", &KB);
|
||||
for(int i = 0; i < KB; i++)
|
||||
for(int i = 0; i < KB; i++)
|
||||
scanf("%d %lf", &B[i].exp, &B[i].coef);
|
||||
|
||||
|
||||
int i = 0, j = 0;
|
||||
while(i < KA || j < KB)
|
||||
{
|
||||
@@ -65,11 +39,11 @@ int main()
|
||||
}
|
||||
if(fabs(sum[Ksum].coef) >= 0.05) Ksum++;
|
||||
}
|
||||
|
||||
|
||||
printf("%d", Ksum);
|
||||
|
||||
for(int i = 0; i < Ksum; i++)
|
||||
|
||||
for(int i = 0; i < Ksum; i++)
|
||||
printf(" %d %.1lf", sum[i].exp, sum[i].coef);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+8
-51
@@ -1,46 +1,3 @@
|
||||
/**
|
||||
* 1003. Emergency (25)
|
||||
*
|
||||
* As an emergency rescue team leader of a city, you are given a special map of
|
||||
* your country. The map shows several scattered cities connected by some roads.
|
||||
* Amount of rescue teams in each city and the length of each road between any
|
||||
* pair of cities are marked on the map. When there is an emergency call to you
|
||||
* from some other city, your job is to lead your men to the place as quickly as
|
||||
* possible, and at the mean time, call up as many hands on the way as possible.
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. For each test case, the first line
|
||||
* contains 4 positive integers: N (<= 500) - the number of cities (and the
|
||||
* cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the
|
||||
* cities that you are currently in and that you must save, respectively. The
|
||||
* next line contains N integers, where the i-th integer is the number of rescue
|
||||
* teams in the i-th city. Then M lines follow, each describes a road with three
|
||||
* integers c1, c2 and L, which are the pair of cities connected by a road and
|
||||
* the length of that road, respectively. It is guaranteed that there exists at
|
||||
* least one path from C1 to C2.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each test case, print in one line two numbers: the number of different
|
||||
* shortest paths between C1 and C2, and the maximum amount of rescue teams you
|
||||
* can possibly gather.
|
||||
* All the numbers in a line must be separated by exactly one space, and there
|
||||
* is no extra space allowed at the end of a line.
|
||||
*
|
||||
* Sample Input
|
||||
* 5 6 0 2
|
||||
* 1 2 1 5 3
|
||||
* 0 1 1
|
||||
* 0 2 2
|
||||
* 0 3 1
|
||||
* 1 2 1
|
||||
* 2 4 1
|
||||
* 3 4 1
|
||||
* Sample Output
|
||||
* 2 4
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
@@ -90,7 +47,7 @@ void Read(Graph G)
|
||||
v->npath = 0;
|
||||
v->adj = NULL;
|
||||
}
|
||||
|
||||
|
||||
int id1, id2, length;
|
||||
for(int i = 0; i < G->nadj; i++)
|
||||
{
|
||||
@@ -110,7 +67,7 @@ void Read(Graph G)
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the shortest path length using Dijkstra alg,
|
||||
/* Find the shortest path length using Dijkstra alg,
|
||||
* in the same time record the number of shortest paths and max rescue teams */
|
||||
void ModifiedDijkstra(Graph G)
|
||||
{
|
||||
@@ -128,7 +85,7 @@ void ModifiedDijkstra(Graph G)
|
||||
v = w;
|
||||
}
|
||||
if(v == NULL) break;
|
||||
|
||||
|
||||
v->known = 1;
|
||||
for(Adj e = v->adj; e; e = e->iter) if(!G->vs[e->id].known)
|
||||
{
|
||||
@@ -155,22 +112,22 @@ int main()
|
||||
{
|
||||
int N, M, C1, C2;
|
||||
scanf("%d %d %d %d", &N, &M, &C1, &C2);
|
||||
|
||||
|
||||
/* Create graph */
|
||||
Vertexes vs = (Vertexes)malloc(N * sizeof(struct Vertex));
|
||||
Adjs es = (Adjs)malloc(M * 2 * sizeof(struct Adj));
|
||||
struct Graph sG = {.vs = vs, .es = es, .nvertex = N, .nadj = M * 2};
|
||||
Graph G = &sG;
|
||||
|
||||
|
||||
/* Read all the data and build the graph */
|
||||
Read(G);
|
||||
G->vs[C1].dist = 0;
|
||||
G->vs[C1].npath = 1;
|
||||
|
||||
|
||||
/* Find the shortest path and maximum rescue teams */
|
||||
ModifiedDijkstra(G);
|
||||
|
||||
|
||||
printf("%d %d", G->vs[C2].npath, G->vs[C2].totrescue);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-39
@@ -1,38 +1,3 @@
|
||||
/**
|
||||
* 1004. Counting Leaves (30)
|
||||
*
|
||||
* A family hierarchy is usually presented by a pedigree tree. Your job is to
|
||||
* count those family members who have no child.
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. Each case starts with a line
|
||||
* containing 0 < N < 100, the number of nodes in a tree, and M (< N), the
|
||||
* number of non-leaf nodes. Then M lines follow, each in the format:
|
||||
*
|
||||
* ID K ID[1] ID[2] ... ID[K]
|
||||
* where ID is a two-digit number representing a given non-leaf node, K is the
|
||||
* number of its children, followed by a sequence of two-digit ID's of its
|
||||
* children. For the sake of simplicity, let us fix the root ID to be 01.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each test case, you are supposed to count those family members who have
|
||||
* no child for every seniority level starting from the root. The numbers must
|
||||
* be printed in a line, separated by a space, and there must be no extra space
|
||||
* at the end of each line.
|
||||
*
|
||||
* The sample case represents a tree with only 2 nodes, where 01 is the root and
|
||||
* 02 is its only child. Hence on the root 01 level, there is 0 leaf node; and
|
||||
* on the next level, there is 1 leaf node. Then we should output "0 1" in a
|
||||
* line.
|
||||
*
|
||||
* Sample Input
|
||||
* 2 1
|
||||
* 01 1 02
|
||||
* Sample Output
|
||||
* 0 1
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX 999
|
||||
@@ -55,7 +20,7 @@ int main()
|
||||
int N, M, ID, cID, K;
|
||||
struct Member nodes[100];
|
||||
struct Child children[100];
|
||||
|
||||
|
||||
/* Read data and initiate a adjacent list */
|
||||
scanf("%d %d", &N, &M);
|
||||
for(int i = 1; i <= N; i++)
|
||||
@@ -75,7 +40,7 @@ int main()
|
||||
nodes[ID].child = &children[k];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* For every level, find leaf nodes */
|
||||
int n = N, count;
|
||||
for(int level = 0; n; level++)
|
||||
@@ -90,9 +55,9 @@ int main()
|
||||
for(Child c = nodes[i].child; c; c = c->iter)
|
||||
nodes[c->ID].level = level + 1;
|
||||
}
|
||||
|
||||
|
||||
printf("%d%c", count, n ? ' ' : '\0');
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-28
@@ -1,26 +1,3 @@
|
||||
/**
|
||||
* 1005. Spell It Right (20)
|
||||
*
|
||||
* Given a non-negative integer N, your task is to compute the sum of all the
|
||||
* digits of N, and output every digit of the sum in English.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case occupies one line which
|
||||
* contains an N (<= 10100).
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, output in one line the digits of the sum in English
|
||||
* words. There must be one space between two consecutive words, but no extra
|
||||
* space at the end of a line.
|
||||
*
|
||||
* Sample Input:
|
||||
* 12345
|
||||
* Sample Output:
|
||||
* one five
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -30,15 +7,15 @@ int main()
|
||||
"zero", "one", "two", "three", "four", "five",
|
||||
"six", "seven", "eight", "nine"
|
||||
};
|
||||
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
sum += c - '0';
|
||||
|
||||
if(sum >= 100)
|
||||
|
||||
if(sum >= 100)
|
||||
printf("%s ", digits[sum / 100]);
|
||||
if(sum >= 10)
|
||||
if(sum >= 10)
|
||||
printf("%s ", digits[sum % 100 / 10]);
|
||||
printf("%s", digits[sum % 10]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-43
@@ -1,40 +1,3 @@
|
||||
/**
|
||||
* 1006. Sign In and Sign Out (25)
|
||||
*
|
||||
* At the beginning of every day, the first person who signs in the computer
|
||||
* room will unlock the door, and the last one who signs out will lock the door.
|
||||
* Given the records of signing in's and out's, you are supposed to find the
|
||||
* ones who have unlocked and locked the door on that day.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case contains the records for
|
||||
* one day. The case starts with a positive integer M, which is the total number
|
||||
* of records, followed by M lines, each in the format:
|
||||
*
|
||||
* ID_number Sign_in_time Sign_out_time
|
||||
* where times are given in the format HH:MM:SS, and ID number is a string with
|
||||
* no more than 15 characters.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, output in one line the ID numbers of the persons who have
|
||||
* unlocked and locked the door on that day. The two ID numbers must be
|
||||
* separated by one space.
|
||||
*
|
||||
* Note: It is guaranteed that the records are consistent. That is, the sign in
|
||||
* time must be earlier than the sign out time for each person, and there are no
|
||||
* two persons sign in or out at the same moment.
|
||||
*
|
||||
* Sample Input:
|
||||
* 3
|
||||
* CS301111 15:30:28 17:00:10
|
||||
* SC3021234 08:00:00 11:25:25
|
||||
* CS301133 21:45:00 21:58:40
|
||||
* Sample Output:
|
||||
* SC3021234 CS301133
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -43,7 +6,7 @@ int main()
|
||||
int N, HH, MM, SS;
|
||||
int firsttime = 86400, lasttime = -1, time;
|
||||
char firstname[16], lastname[16], name[16];
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -54,17 +17,17 @@ int main()
|
||||
firsttime = time;
|
||||
strcpy(firstname, name);
|
||||
}
|
||||
|
||||
|
||||
scanf("%d:%d:%d", &HH, &MM, &SS);
|
||||
time = (HH * 60 + MM) * 60 + SS;
|
||||
if(time > lasttime)
|
||||
{
|
||||
{
|
||||
lasttime = time;
|
||||
strcpy(lastname, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("%s %s", firstname, lastname);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-40
@@ -1,38 +1,3 @@
|
||||
/**
|
||||
* 1007. Maximum Subsequence Sum (25)
|
||||
*
|
||||
* Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence
|
||||
* is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum
|
||||
* Subsequence is the continuous subsequence which has the largest sum of its
|
||||
* elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum
|
||||
* subsequence is { 11, -4, 13 } with the largest sum being 20.
|
||||
*
|
||||
* Now you are supposed to find the largest sum, together with the first and the
|
||||
* last numbers of the maximum subsequence.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case occupies two lines. The
|
||||
* first line contains a positive integer K (<= 10000). The second line contains
|
||||
* K numbers, separated by a space.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, output in one line the largest sum, together with the
|
||||
* first and the last numbers of the maximum subsequence. The numbers must be
|
||||
* separated by one space, but there must be no extra space at the end of a
|
||||
* line. In case that the maximum subsequence is not unique, output the one with
|
||||
* the smallest indices i and j (as shown by the sample case). If all the K
|
||||
* numbers are negative, then its maximum sum is defined to be 0, and you are
|
||||
* supposed to output the first and the last numbers of the whole sequence.
|
||||
*
|
||||
* Sample Input:
|
||||
* 10
|
||||
* -10 1 2 3 4 -5 -23 3 7 -21
|
||||
* Sample Output:
|
||||
* 10 1 4
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -40,25 +5,25 @@ int main()
|
||||
int K, n, first;
|
||||
int start, end, sum = -1; /* the current non-negative subsequence */
|
||||
int a = -1, b, s = 0; /* the maximum-sum subsequence */
|
||||
|
||||
|
||||
scanf("%d", &K);
|
||||
for(int i = 0; i < K; i++)
|
||||
{
|
||||
scanf("%d", &n);
|
||||
if(i == 0) first = n; /* record the first number */
|
||||
|
||||
|
||||
/* update start, end and sum for the current non-negative subsequence */
|
||||
if(sum < 0) start = n, sum = 0; /* reset if sum < 0 */
|
||||
sum += n; /* update sum */
|
||||
if(sum >= 0) end = n; /* update end if sum >= 0 */
|
||||
|
||||
|
||||
/* update a, b and s for the so-far maximum-sum subsequence */
|
||||
if(sum > s || (!sum && !s)) /* special case is max-sum is 0 */
|
||||
a = start, b = end, s = sum;
|
||||
}
|
||||
/* a won't be updated if all the numbers are negative */
|
||||
if(a == -1) printf("0 %d %d", first, n);
|
||||
if(a == -1) printf("0 %d %d", first, n);
|
||||
else printf("%d %d %d", s, a, b);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-32
@@ -1,37 +1,8 @@
|
||||
/**
|
||||
* 1008. Elevator (20)
|
||||
*
|
||||
* The highest building in our city has only one elevator. A request list is
|
||||
* made up with N positive numbers. The numbers denote at which floors the
|
||||
* elevator will stop, in specified order. It costs 6 seconds to move the
|
||||
* elevator up one floor, and 4 seconds to move down one floor. The elevator
|
||||
* will stay for 5 seconds at each stop.
|
||||
*
|
||||
* For a given request list, you are to compute the total time spent to fulfill
|
||||
* the requests on the list. The elevator is on the 0th floor at the beginning
|
||||
* and does not have to return to the ground floor when the requests are
|
||||
* fulfilled.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case contains a positive integer
|
||||
* N, followed by N positive numbers. All the numbers in the input are less than
|
||||
* 100.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, print the total time on a single line.
|
||||
*
|
||||
* Sample Input:
|
||||
* 3 2 3 1
|
||||
* Sample Output:
|
||||
* 41
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int N, time, cur, pre;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(pre = 0, time = 0; N--; pre = cur)
|
||||
{
|
||||
@@ -39,8 +10,8 @@ int main()
|
||||
if(cur > pre) time += (cur - pre) * 6 + 5;
|
||||
else time += (pre - cur) * 4 + 5;
|
||||
}
|
||||
|
||||
|
||||
printf("%d", time);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-30
@@ -1,29 +1,3 @@
|
||||
/**
|
||||
* 1009. Product of Polynomials (25)
|
||||
*
|
||||
* This time, you are supposed to find A*B where A and B are two polynomials.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case occupies 2 lines, and each
|
||||
* line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK,
|
||||
* where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2,
|
||||
* ..., K) are the exponents and coefficients, respectively. It is given that 1
|
||||
* <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case you should output the product of A and B in one line, with
|
||||
* the same format as the input. Notice that there must be NO extra space at the
|
||||
* end of each line. Please be accurate up to 1 decimal place.
|
||||
*
|
||||
* Sample Input
|
||||
* 2 1 2.4 0 3.2
|
||||
* 2 2 1.5 1 0.5
|
||||
* Sample Output
|
||||
* 3 3 3.6 2 6.0 1 1.6
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
@@ -38,13 +12,13 @@ int main()
|
||||
for(int i = 0; i < 1001; i++)
|
||||
for(int j = 0; j < 1001; j++)
|
||||
MUL[i + j] += A[i] * B[j];
|
||||
|
||||
|
||||
for(int i = 0; i < 2001; i++)
|
||||
if(MUL[i]) count++;
|
||||
|
||||
|
||||
printf("%d", count);
|
||||
for(int i = 2000; i >= 0; i--) if(MUL[i])
|
||||
for(int i = 2000; i >= 0; i--) if(MUL[i])
|
||||
printf(" %d %.1f", i, MUL[i]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-41
@@ -1,39 +1,3 @@
|
||||
/**
|
||||
* 1010. Radix (25)
|
||||
*
|
||||
* Given a pair of positive integers, for example, 6 and 110, can this equation
|
||||
* 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a
|
||||
* binary number.
|
||||
*
|
||||
* Now for any pair of positive integers N1 and N2, your task is to find the
|
||||
* radix of one number while that of the other is given.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case occupies a line which
|
||||
* contains 4 positive integers:
|
||||
* N1 N2 tag radix
|
||||
* Here N1 and N2 each has no more than 10 digits. A digit is less than its
|
||||
* radix and is chosen from the set {0-9, a-z} where 0-9 represent the decimal
|
||||
* numbers 0-9, and a-z represent the decimal numbers 10-35. The last number
|
||||
* "radix" is the radix of N1 if "tag" is 1, or of N2 if "tag" is 2.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, print in one line the radix of the other number so that
|
||||
* the equation N1 = N2 is true. If the equation is impossible, print
|
||||
* "Impossible". If the solution is not unique, output the smallest possible
|
||||
* radix.
|
||||
*
|
||||
* Sample Input 1:
|
||||
* 6 110 1 10
|
||||
* Sample Output 1:
|
||||
* 2
|
||||
* Sample Input 2:
|
||||
* 1 ab 1 2
|
||||
* Sample Output 2:
|
||||
* Impossible
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
@@ -61,7 +25,7 @@ long long base10(char *s, long long radix)
|
||||
int minradix(char *s)
|
||||
{ /* Simply the largest digit in the number plus 1 */
|
||||
char r;
|
||||
for(r = '0'; *s; s++)
|
||||
for(r = '0'; *s; s++)
|
||||
if(*s > r)
|
||||
r = *s;
|
||||
return CBASE10(r) + 1;
|
||||
@@ -74,7 +38,7 @@ long long binsearch(char *s, long long n, long long rmin, long long rmax)
|
||||
while(rmax >= rmin)
|
||||
{
|
||||
r = rmin + (rmax - rmin) / 2; /* avoid (rmin + rmax) overflow */
|
||||
if((m = base10(s, r)) > n || m == OVERFLOW)
|
||||
if((m = base10(s, r)) > n || m == OVERFLOW)
|
||||
rmax = r - 1;
|
||||
else if(m < n)
|
||||
rmin = r + 1;
|
||||
@@ -89,12 +53,12 @@ int main()
|
||||
int tag, radix;
|
||||
long long N1, rmin, rmax, r;
|
||||
char buf1[11], buf2[11], *S1, *S2;
|
||||
|
||||
|
||||
/* Make S1 point to the number with known radix, S2 to the other */
|
||||
scanf("%s %s %d %d", buf1, buf2, &tag, &radix);
|
||||
if(tag == 1) S1 = buf1, S2 = buf2;
|
||||
if(tag == 2) S1 = buf2, S2 = buf1;
|
||||
|
||||
|
||||
N1 = base10(S1, radix); /* Corresponding decimal of S1 */
|
||||
rmin = minradix(S2); /* Smallest possible radix of S2 */
|
||||
rmax = LLONG_MAX; /* Largest possible radix of S2 */
|
||||
@@ -109,6 +73,6 @@ int main()
|
||||
if(r != NOTFOUNT) printf("%lld", r);
|
||||
else printf("Impossible");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-48
@@ -1,56 +1,10 @@
|
||||
/**
|
||||
* 1011. World Cup Betting (20)
|
||||
*
|
||||
* With the 2010 FIFA World Cup running, football fans the world over were
|
||||
* becoming increasingly excited as the best players from the best teams doing
|
||||
* battles for the World Cup trophy in South Africa. Similarly, football betting
|
||||
* fans were putting their money where their mouths were, by laying all manner
|
||||
* of World Cup bets.
|
||||
*
|
||||
* Chinese Football Lottery provided a "Triple Winning" game. The rule of
|
||||
* winning was simple: first select any three of the games. Then for each
|
||||
* selected game, bet on one of the three possible results -- namely W for win,
|
||||
* T for tie, and L for lose. There was an odd assigned to each result. The
|
||||
* winner's odd would be the product of the three odds times 65%.
|
||||
*
|
||||
* For example, 3 games' odds are given as the following:
|
||||
*
|
||||
* W T L
|
||||
* 1.1 2.5 1.7
|
||||
* 1.2 3.0 1.6
|
||||
* 4.1 1.2 1.1
|
||||
* To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd
|
||||
* game, and T for the 1st game. If each bet takes 2 yuans, then the maximum
|
||||
* profit would be (4.1*3.0*2.5*65%-1)*2 = 37.98 yuans (accurate up to 2 decimal
|
||||
* places).
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. Each case contains the betting
|
||||
* information of 3 games. Each game occupies a line with three distinct odds
|
||||
* corresponding to W, T and L.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each test case, print in one line the best bet of each game, and the
|
||||
* maximum profit accurate up to 2 decimal places. The characters and the number
|
||||
* must be separated by one space.
|
||||
*
|
||||
* Sample Input
|
||||
* 1.1 2.5 1.7
|
||||
* 1.2 3.0 1.6
|
||||
* 4.1 1.2 1.1
|
||||
* Sample Output
|
||||
* T T W 37.98
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c;
|
||||
float odd, maxodd, maxprofit = 1;
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
maxodd = 0;
|
||||
@@ -67,6 +21,6 @@ int main()
|
||||
maxprofit *= maxodd;
|
||||
}
|
||||
printf("%.2f", (maxprofit * 0.65 - 1) * 2);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-71
@@ -1,68 +1,3 @@
|
||||
/**
|
||||
* 1012. The Best Rank (25)
|
||||
*
|
||||
* To evaluate the performance of our first year CS majored students, we
|
||||
* consider their grades of three courses only: C - C Programming Language, M -
|
||||
* Mathematics (Calculus or Linear Algebra), and E - English. At the mean time,
|
||||
* we encourage students by emphasizing on their best ranks -- that is, among
|
||||
* the four ranks with respect to the three courses and the average grade, we
|
||||
* print the best rank for each student.
|
||||
*
|
||||
* For example, The grades of C, M, E and A - Average of 4 students are given as
|
||||
* the following:
|
||||
*
|
||||
* StudentID C M E A
|
||||
* 310101 98 85 88 90
|
||||
* 310102 70 95 88 84
|
||||
* 310103 82 87 94 88
|
||||
* 310104 91 91 91 91
|
||||
* Then the best ranks for all the students are No.1 since the 1st one has done
|
||||
* the best in C Programming Language, while the 2nd one in Mathematics, the 3rd
|
||||
* one in English, and the last one in average.
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. Each case starts with a line
|
||||
* containing 2 numbers N and M (<=2000), which are the total number of
|
||||
* students, and the number of students who would check their ranks,
|
||||
* respectively. Then N lines follow, each contains a student ID which is a
|
||||
* string of 6 digits, followed by the three integer grades (in the range of
|
||||
* [0, 100]) of that student in the order of C, M and E. Then there are M lines,
|
||||
* each containing a student ID.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each of the M students, print in one line the best rank for him/her, and
|
||||
* the symbol of the corresponding rank, separated by a space.
|
||||
*
|
||||
* The priorities of the ranking methods are ordered as A > C > M > E. Hence if
|
||||
* there are two or more ways for a student to obtain the same best rank, output
|
||||
* the one with the highest priority.
|
||||
*
|
||||
* If a student is not on the grading list, simply output "N/A".
|
||||
*
|
||||
* Sample Input
|
||||
* 5 6
|
||||
* 310101 98 85 88
|
||||
* 310102 70 95 88
|
||||
* 310103 82 87 94
|
||||
* 310104 91 91 91
|
||||
* 310105 85 90 90
|
||||
* 310101
|
||||
* 310102
|
||||
* 310103
|
||||
* 310104
|
||||
* 310105
|
||||
* 999999
|
||||
* Sample Output
|
||||
* 1 C
|
||||
* 1 M
|
||||
* 1 E
|
||||
* 1 A
|
||||
* 3 A
|
||||
* N/A
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct Student{ int ID, score[4]; } Student;
|
||||
@@ -71,29 +6,29 @@ int main()
|
||||
{
|
||||
/* scores array stores the number of students of any score */
|
||||
int N, M, ID, scores[4][102] = {{0}};
|
||||
|
||||
|
||||
/* Setting a score of 101 is to make it easy to calculate rank */
|
||||
scores[0][101] = scores[1][101] = scores[2][101] = scores[3][101] = 1;
|
||||
Student students[2000];
|
||||
|
||||
|
||||
scanf("%d %d", &N, &M);
|
||||
for(int i = 0; i < N; i++)
|
||||
{ /* record all the scores for every student: A, C, M, E */
|
||||
Student *s = students + i;
|
||||
scanf("%d %d %d %d", &s->ID, &s->score[1], &s->score[2], &s->score[3]);
|
||||
s->score[0] = (s->score[1] + s->score[2] + s->score[3] + 1) / 3;
|
||||
s->score[0] = (s->score[1] + s->score[2] + s->score[3] + 1) / 3;
|
||||
for(int j = 0; j < 4; j++) /* +1 for rounding */
|
||||
scores[j][s->score[j]]++; /* record how many got this score */
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < M; i++)
|
||||
{
|
||||
int max = 3, ranks[4] = {0}, stu;
|
||||
|
||||
|
||||
scanf("%d", &ID);
|
||||
for(stu = 0; stu < N && students[stu].ID != ID; stu++) ; /* find */
|
||||
if(stu == N) { puts("N/A"); continue;}
|
||||
|
||||
|
||||
for(int j = 3; j >= 0; j--)
|
||||
{ /* calculate the rank: sum the counts from score + 1 to 101 */
|
||||
/* e.g. score 100 will have rank 1, since scores[101] is 1 */
|
||||
|
||||
@@ -1,43 +1,3 @@
|
||||
/**
|
||||
* 1013. Battle Over Cities (25)
|
||||
*
|
||||
* It is vitally important to have all the cities connected by highways in a
|
||||
* war. If a city is occupied by the enemy, all the highways from/toward that
|
||||
* city are closed. We must know immediately if we need to repair any other
|
||||
* highways to keep the rest of the cities connected. Given the map of cities
|
||||
* which have all the remaining highways marked, you are supposed to tell the
|
||||
* number of highways need to be repaired, quickly.
|
||||
*
|
||||
* For example, if we have 3 cities and 2 highways connecting city1-city2 and
|
||||
* city1-city3. Then if city1 is occupied by the enemy, we must have 1 highway
|
||||
* repaired, that is the highway city2-city3.
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. Each case starts with a line
|
||||
* containing 3 numbers N (<1000), M and K, which are the total number of
|
||||
* cities, the number of remaining highways, and the number of cities to be
|
||||
* checked, respectively. Then M lines follow, each describes a highway by 2
|
||||
* integers, which are the numbers of the cities the highway connects. The
|
||||
* cities are numbered from 1 to N. Finally there is a line containing K
|
||||
* numbers, which represent the cities we concern.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each of the K cities, output in a line the number of highways need to be
|
||||
* repaired if that city is lost.
|
||||
*
|
||||
* Sample Input
|
||||
* 3 2 3
|
||||
* 1 2
|
||||
* 1 3
|
||||
* 1 2 3
|
||||
* Sample Output
|
||||
* 1
|
||||
* 0
|
||||
* 0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX 1000
|
||||
|
||||
+4
-71
@@ -1,70 +1,3 @@
|
||||
/**
|
||||
* 1014. Waiting in Line (30)
|
||||
*
|
||||
* Suppose a bank has N windows open for service. There is a yellow line in
|
||||
* front of the windows which devides the waiting area into two parts. The rules
|
||||
* for the customers to wait in line are:
|
||||
*
|
||||
* The space inside the yellow line in front of each window is enough to
|
||||
* contain a line with M customers. Hence when all the N lines are full, all the
|
||||
* customers after (and including) the (NM+1)st one will have to wait in a line
|
||||
* behind the yellow line.
|
||||
* Each customer will choose the shortest line to wait in when crossing the
|
||||
* yellow line. If there are two or more lines with the same length, the
|
||||
* customer will always choose the window with the smallest number.
|
||||
* Customer[i] will take T[i] minutes to have his/her transaction processed.
|
||||
* The first N customers are assumed to be served at 8:00am.
|
||||
*
|
||||
* Now given the processing time of each customer, you are supposed to tell the
|
||||
* exact time at which a customer has his/her business done.
|
||||
*
|
||||
* For example, suppose that a bank has 2 windows and each window may have 2
|
||||
* custmers waiting inside the yellow line. There are 5 customers waiting with
|
||||
* transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the
|
||||
* morning, customer1 is served at window1 while customer2 is served at window2.
|
||||
* Customer3 will wait in front of window1 and customer4 will wait in front of
|
||||
* window2. Customer5 will wait behind the yellow line.
|
||||
*
|
||||
* At 08:01, customer1 is done and customer5 enters the line in front of window1
|
||||
* since that line seems shorter now. Customer2 will leave at 08:02, customer4
|
||||
* at 08:06, customer3 at 08:07, and finally customer5 at 08:10.
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* Each input file contains one test case. Each case starts with a line
|
||||
* containing 4 positive integers: N (<=20, number of windows), M (<=10, the
|
||||
* maximum capacity of each line inside the yellow line), K (<=1000, number of
|
||||
* customers), and Q (<=1000, number of customer queries).
|
||||
*
|
||||
* The next line contains K positive integers, which are the processing time of
|
||||
* the K customers.
|
||||
*
|
||||
* The last line contains Q positive integers, which represent the customers who
|
||||
* are asking about the time they can have their transactions done. The
|
||||
* customers are numbered from 1 to K.
|
||||
*
|
||||
* Output
|
||||
*
|
||||
* For each of the Q customers, print in one line the time at which his/her
|
||||
* transaction is finished, in the format HH:MM where HH is in [08, 17] and MM
|
||||
* is in [00, 59]. Note that since the bank is closed everyday after 17:00, for
|
||||
* those customers who cannot be served before 17:00, you must output "Sorry"
|
||||
* instead.
|
||||
* Sample Input
|
||||
*
|
||||
* 2 2 7 5
|
||||
* 1 2 6 4 3 534 2
|
||||
* 3 4 5 6 7
|
||||
*
|
||||
* Sample Output
|
||||
*
|
||||
* 08:07
|
||||
* 08:06
|
||||
* 08:10
|
||||
* 17:00
|
||||
* Sorry
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define LATE_FLAG -1
|
||||
@@ -77,11 +10,11 @@ int main()
|
||||
int N, M, K, Q, query;
|
||||
int time[1000], queue[20][11] = {{0}};
|
||||
int front[20] = {0}, rear[20] = {0}, length[20] = {0};
|
||||
|
||||
|
||||
scanf("%d %d %d %d", &N, &M, &K, &Q);
|
||||
for(int i = 1; i <= K; i++)
|
||||
scanf("%d", time + i);
|
||||
|
||||
|
||||
/* Total number of operations */
|
||||
int count = (K < M * N) ? (2 * K) : (K + M * N);
|
||||
/* Doing dequeues and enqueues for every customer */
|
||||
@@ -121,7 +54,7 @@ int main()
|
||||
length[shortest]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Read queries and print answers */
|
||||
for(int i = 0; i < Q; i++)
|
||||
{
|
||||
@@ -131,6 +64,6 @@ int main()
|
||||
else
|
||||
printf("Sorry\n");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-34
@@ -1,35 +1,3 @@
|
||||
/**
|
||||
* 1015. Reversible Primes (20)
|
||||
*
|
||||
* A reversible prime in any number system is a prime whose "reverse" in
|
||||
* that number system is also a prime. For example in the decimal system
|
||||
* 73 is a reversible prime because its reverse 37 is also a prime.
|
||||
*
|
||||
* Now given any two positive integers N (< 105) and D (1 < D <= 10),
|
||||
* you are supposed to tell if N is a reversible prime with radix D.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* The input file consists of several test cases. Each case occupies a
|
||||
* line which contains two integers N and D. The input is finished by a
|
||||
* negative N.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, print in one line "Yes" if N is a reversible
|
||||
* prime with radix D, or "No" if not.
|
||||
*
|
||||
* Sample Input:
|
||||
* 73 10
|
||||
* 23 2
|
||||
* 23 10
|
||||
* -2
|
||||
* Sample Output:
|
||||
* Yes
|
||||
* Yes
|
||||
* No
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int iPrime(int N)
|
||||
@@ -46,8 +14,8 @@ int Rev(int N, int D)
|
||||
{
|
||||
int Nrev;
|
||||
for(Nrev = 0; N; N /= D)
|
||||
{
|
||||
Nrev *= D;
|
||||
{
|
||||
Nrev *= D;
|
||||
Nrev += N % D;
|
||||
}
|
||||
return Nrev;
|
||||
|
||||
+11
-88
@@ -1,80 +1,3 @@
|
||||
/**
|
||||
* 1016. Phone Bills (25)
|
||||
*
|
||||
* A long-distance telephone company charges its customers by the following
|
||||
* rules:
|
||||
*
|
||||
* Making a long-distance call costs a certain amount per minute, depending on
|
||||
* the time of day when the call is made. When a customer starts connecting a
|
||||
* long-distance call, the time will be recorded, and so will be the time when
|
||||
* the customer hangs up the phone. Every calendar month, a bill is sent to the
|
||||
* customer for each minute called (at a rate determined by the time of day).
|
||||
* Your job is to prepare the bills for each month, given a set of phone call
|
||||
* records.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case has two parts: the rate
|
||||
* structure, and the phone call records.
|
||||
*
|
||||
* The rate structure consists of a line with 24 non-negative integers denoting
|
||||
* the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and
|
||||
* so on for each hour in the day.
|
||||
*
|
||||
* The next line contains a positive number N (<= 1000), followed by N lines of
|
||||
* records. Each phone call record consists of the name of the customer (string
|
||||
* of up to 20 characters without space), the time and date (mm:dd:hh:mm), and
|
||||
* the word "on-line" or "off-line".
|
||||
*
|
||||
* For each test case, all dates will be within a single month. Each "on-line"
|
||||
* record is paired with the chronologically next record for the same customer
|
||||
* provided it is an "off-line" record. Any "on-line" records that are not
|
||||
* paired with an "off-line" record are ignored, as are "off-line" records not
|
||||
* paired with an "on-line" record. It is guaranteed that at least one call is
|
||||
* well paired in the input. You may assume that no two records for the same
|
||||
* customer have the same time. Times are recorded using a 24-hour clock.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, you must print a phone bill for each customer.
|
||||
*
|
||||
* Bills must be printed in alphabetical order of customers' names. For each
|
||||
* customer, first print in a line the name of the customer and the month of
|
||||
* the bill in the format shown by the sample. Then for each time period of a
|
||||
* call, print in one line the beginning and ending time and date (dd:hh:mm),
|
||||
* the lasting time (in minute) and the charge of the call. The calls must be
|
||||
* listed in chronological order. Finally, print the total charge for the month
|
||||
* in the format shown by the sample.
|
||||
*
|
||||
* Sample Input:
|
||||
*
|
||||
* 10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
|
||||
* 10
|
||||
* CYLL 01:01:06:01 on-line
|
||||
* CYLL 01:28:16:05 off-line
|
||||
* CYJJ 01:01:07:00 off-line
|
||||
* CYLL 01:01:08:03 off-line
|
||||
* CYJJ 01:01:05:59 on-line
|
||||
* aaa 01:01:01:03 on-line
|
||||
* aaa 01:02:00:01 on-line
|
||||
* CYLL 01:28:15:41 on-line
|
||||
* aaa 01:05:02:24 on-line
|
||||
* aaa 01:04:23:59 off-line
|
||||
*
|
||||
* Sample Output:
|
||||
*
|
||||
* CYJJ 01
|
||||
* 01:05:59 01:07:00 61 $12.10
|
||||
* Total amount: $12.10
|
||||
* CYLL 01
|
||||
* 01:06:01 01:08:03 122 $24.40
|
||||
* 28:15:41 28:16:05 24 $3.85
|
||||
* Total amount: $28.25
|
||||
* aaa 01
|
||||
* 02:00:01 04:23:59 4318 $638.80
|
||||
* Total amount: $638.80
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -89,7 +12,7 @@ typedef struct {
|
||||
int cmp(const void *record1, const void *record2)
|
||||
{
|
||||
pRecord r1 = *(pRecord*)record1, r2 = *(pRecord*)record2;
|
||||
return strcmp(r1->name, r2->name) ?
|
||||
return strcmp(r1->name, r2->name) ?
|
||||
strcmp(r1->name, r2->name) : r1->time - r2->time;
|
||||
}
|
||||
|
||||
@@ -97,14 +20,14 @@ int cmp(const void *record1, const void *record2)
|
||||
int calccharge(pRecord p1, pRecord p2, int toll[])
|
||||
{
|
||||
int charge = 0, start = p1->time, end = p2->time, h, time1, time2;
|
||||
|
||||
|
||||
for(time1 = start; time1 < end; time1 = time2)
|
||||
{ /* Add the charge hour by hour */
|
||||
time2 = (time1 / 60 + 1) * 60; /* time2 will be the time of next hour */
|
||||
h = time1 / 60 % 24; /* h will be the index of the hour */
|
||||
charge += ((time2 > end ? end : time2) - time1) * toll[h];
|
||||
}
|
||||
|
||||
|
||||
return charge;
|
||||
}
|
||||
|
||||
@@ -114,7 +37,7 @@ int main()
|
||||
int N, toll[24], charge, charge_total = 0;
|
||||
Record records[1001] = {0};
|
||||
pRecord precords[1001] = {0}, *p = precords;
|
||||
|
||||
|
||||
/* Read data */
|
||||
for(int i = 0; i < 24; i++)
|
||||
scanf("%d", toll + i);
|
||||
@@ -122,18 +45,18 @@ int main()
|
||||
for(int i = 0; i < N; i++, p++)
|
||||
{
|
||||
*p = records + i;
|
||||
scanf("%s %d:%d:%d:%d %s", (*p)->name,
|
||||
scanf("%s %d:%d:%d:%d %s", (*p)->name,
|
||||
&(*p)->month, &(*p)->day, &(*p)->hour, &(*p)->min, state);
|
||||
(*p)->time = ((*p)->day * 24 + (*p)->hour) * 60 + (*p)->min;
|
||||
(*p)->state = strcmp(state, "on-line") ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
/* Sort first by name, then by date and time */
|
||||
qsort(precords, N, sizeof(pRecord), cmp);
|
||||
|
||||
|
||||
/* Print phone bill one by one */
|
||||
for(p = precords + 1; *p; p++)
|
||||
{
|
||||
{
|
||||
if(strcmp((*p)->name, (*(p - 1))->name))
|
||||
{ /* A new customer, print last total amount if any */
|
||||
if(charge_total)
|
||||
@@ -147,14 +70,14 @@ int main()
|
||||
charge = calccharge(*(p - 1), *p, toll);
|
||||
charge_total += charge;
|
||||
/* Print info of this call */
|
||||
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",
|
||||
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",
|
||||
(*(p - 1))->day, (*(p - 1))->hour, (*(p - 1))->min,
|
||||
(*p)->day, (*p)->hour, (*p)->min,
|
||||
(*p)->time - (*(p - 1))->time, charge * 1e-2);
|
||||
(*p)->time - (*(p - 1))->time, charge * 1e-2);
|
||||
}
|
||||
}
|
||||
if(charge_total)
|
||||
printf("Total amount: $%.2f\n", charge_total * 1e-2);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+8
-53
@@ -1,48 +1,3 @@
|
||||
/**
|
||||
* 1017. Queueing at Bank (25)
|
||||
*
|
||||
* Suppose a bank has K windows open for service. There is a yellow line in
|
||||
* front of the windows which devides the waiting area into two parts. All the
|
||||
* customers have to wait in line behind the yellow line, until it is his/her
|
||||
* turn to be served and there is a window available. It is assumed that no
|
||||
* window can be occupied by a single customer for more than 1 hour.
|
||||
*
|
||||
* Now given the arriving time T and the processing time P of each customer, you
|
||||
* are supposed to tell the average waiting time of all the customers.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. For each case, the first line
|
||||
* contains 2 numbers: N (<=10000) - the total number of customers, and K
|
||||
* (<=100) - the number of windows. Then N lines follow, each contains 2 times:
|
||||
* HH:MM:SS - the arriving time, and P - the processing time in minutes of a
|
||||
* customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59].
|
||||
* It is assumed that no two customers arrives at the same time.
|
||||
*
|
||||
* Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will
|
||||
* have to wait in line till 08:00, and anyone comes too late (at or after
|
||||
* 17:00:01) will not be served nor counted into the average.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, print in one line the average waiting time of all the
|
||||
* customers, in minutes and accurate up to 1 decimal place.
|
||||
* Sample Input:
|
||||
*
|
||||
* 7 3
|
||||
* 07:55:00 16
|
||||
* 17:00:01 2
|
||||
* 07:59:59 15
|
||||
* 08:01:00 60
|
||||
* 08:00:00 30
|
||||
* 08:00:02 2
|
||||
* 08:03:00 10
|
||||
*
|
||||
* Sample Output:
|
||||
*
|
||||
* 8.2
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -64,7 +19,7 @@ int main()
|
||||
int HH, MM, SS;
|
||||
int wait_time = 0, queue_time[100] = {0};
|
||||
Customer customers[10000], *p;
|
||||
|
||||
|
||||
scanf("%d %d", &N, &K);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -73,26 +28,26 @@ int main()
|
||||
customers[i].start = SS + 60 * (MM + 60 * (HH - 8));
|
||||
customers[i].len *= 60;
|
||||
}
|
||||
|
||||
|
||||
qsort(customers, N, sizeof(Customer), cmp);
|
||||
|
||||
|
||||
for(i = 0; i < N; i++)
|
||||
{
|
||||
p = customers + i;
|
||||
|
||||
|
||||
/* Find the queue number which will finish next */
|
||||
earliest = 0;
|
||||
for(int i = 0; i < K; i++)
|
||||
if(queue_time[i] < queue_time[earliest])
|
||||
earliest = i;
|
||||
|
||||
|
||||
/* later than 17:00:00 */
|
||||
if(p->start > (17 - 8) * 3600)
|
||||
break;
|
||||
/* processing time longer than one hour */
|
||||
if(p->len > 3600)
|
||||
p->len = 3600;
|
||||
|
||||
|
||||
/* increase total waiting time and modify the time of each queue */
|
||||
if(p->start < queue_time[earliest])
|
||||
{
|
||||
@@ -104,11 +59,11 @@ int main()
|
||||
queue_time[earliest] = p->start + p->len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(i)
|
||||
printf("%.1f", wait_time / 60.0 / i);
|
||||
else
|
||||
printf("0.0");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,52 +1,3 @@
|
||||
/**
|
||||
* 1019. General Palindromic Number (20)
|
||||
*
|
||||
* A number that will be the same when it is written forwards or backwards is
|
||||
* known as a Palindromic Number. For example, 1234321 is a palindromic number.
|
||||
* All single digit numbers are palindromic numbers.
|
||||
*
|
||||
* Although palindromic numbers are most often considered in the decimal system,
|
||||
* the concept of palindromicity can be applied to the natural numbers in any
|
||||
* numeral system. Consider a number N > 0 in base b >= 2, where it is written
|
||||
* in standard notation with k+1 digits ai as the sum of (aibi) for i from 0 to
|
||||
* k. Here, as usual, 0 <= ai < b for all i and ak is non-zero. Then N is
|
||||
* palindromic if and only if ai = ak-i for all i. Zero is written 0 in any base
|
||||
* and is also palindromic by definition.
|
||||
*
|
||||
* Given any non-negative decimal integer N and a base b, you are supposed to
|
||||
* tell if N is a palindromic number in base b.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. Each case consists of two non-
|
||||
* negative numbers N and b, where 0 <= N <= 109 is the decimal number and
|
||||
* 2 <= b <= 109 is the base. The numbers are separated by a space.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, first print in one line "Yes" if N is a palindromic
|
||||
* number in base b, or "No" if not. Then in the next line, print N as the
|
||||
* number in base b in the form "ak ak-1 ... a0". Notice that there must be no
|
||||
* extra space at the end of output.
|
||||
* Sample Input 1:
|
||||
*
|
||||
* 27 2
|
||||
*
|
||||
* Sample Output 1:
|
||||
*
|
||||
* Yes
|
||||
* 1 1 0 1 1
|
||||
*
|
||||
* Sample Input 2:
|
||||
*
|
||||
* 121 5
|
||||
*
|
||||
* Sample Output 2:
|
||||
*
|
||||
* No
|
||||
* 4 4 1
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
+3
-33
@@ -1,33 +1,3 @@
|
||||
/**
|
||||
* 1020. Tree Traversals (25)
|
||||
*
|
||||
* Suppose that all the keys in a binary tree are distinct positive integers.
|
||||
* Given the postorder and inorder traversal sequences, you are supposed to
|
||||
* output the level order traversal sequence of the corresponding binary tree.
|
||||
*
|
||||
* Input Specification:
|
||||
*
|
||||
* Each input file contains one test case. For each case, the first line gives a
|
||||
* positive integer N (<=30), the total number of nodes in the binary tree. The
|
||||
* second line gives the postorder sequence and the third line gives the inorder
|
||||
* sequence. All the numbers in a line are separated by a space.
|
||||
*
|
||||
* Output Specification:
|
||||
*
|
||||
* For each test case, print in one line the level order traversal sequence of
|
||||
* the corresponding binary tree. All the numbers in a line must be separated by
|
||||
* exactly one space, and there must be no extra space at the end of the line.
|
||||
* Sample Input:
|
||||
*
|
||||
* 7
|
||||
* 2 3 1 5 7 6 4
|
||||
* 1 2 3 4 5 6 7
|
||||
*
|
||||
* Sample Output:
|
||||
*
|
||||
* 4 1 6 3 5 7 2
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define QLEN 15
|
||||
@@ -62,13 +32,13 @@ int main()
|
||||
int post[CNODE] = {0}, in[CNODE] = {0}, N;
|
||||
queue q = {0}; /* Initialize to zeros or NULL array */
|
||||
int root, index, count;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
scanf("%d", post + i);
|
||||
for(int i = 0; i < N; i++)
|
||||
scanf("%d", in + i);
|
||||
|
||||
|
||||
node nodes[CNODE] = {{post, in, N}}, *p = nodes, *n;
|
||||
enqueue(&q, p++);
|
||||
for(count = 0; q.count; count++)
|
||||
@@ -95,6 +65,6 @@ int main()
|
||||
/* print */
|
||||
printf("%d%c", root, (count == N - 1) ? '\0' : ' ');
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-29
@@ -1,41 +1,17 @@
|
||||
/**
|
||||
* 1001. 害死人不偿命的(3n+1)猜想
|
||||
* 卡拉兹(Callatz)猜想:
|
||||
*
|
||||
* 对任何一个自然数n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把(3n+1)砍
|
||||
* 掉一半。这样一直反复砍下去,最后一定在某一步得到n=1。卡拉兹在1950年的世界数学家
|
||||
* 大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的
|
||||
* 命题,结果闹得学生们无心学业,一心只证(3n+1),以至于有人说这是一个阴谋,卡拉兹是
|
||||
* 在蓄意延缓美国数学界教学与科研的进展……
|
||||
*
|
||||
* 我们今天的题目不是证明卡拉兹猜想,而是对给定的任一不超过1000的正整数n,简单地数
|
||||
* 一下,需要多少步(砍几下)才能得到n=1?
|
||||
*
|
||||
* 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。
|
||||
*
|
||||
* 输出格式:输出从n计算到1需要的步数。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3
|
||||
*
|
||||
* 输出样例:
|
||||
* 5
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int number, steps;
|
||||
scanf("%d", &number);
|
||||
|
||||
for(steps = 0; number != 1; steps++)
|
||||
if(number % 2 == 0)
|
||||
|
||||
for(steps = 0; number != 1; steps++)
|
||||
if(number % 2 == 0)
|
||||
number /= 2;
|
||||
else
|
||||
number = (3 * number + 1) / 2;
|
||||
|
||||
|
||||
printf("%d", steps);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-20
@@ -1,35 +1,19 @@
|
||||
/**
|
||||
* 1002. 写出这个数
|
||||
* 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
|
||||
*
|
||||
* 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10^100。
|
||||
*
|
||||
* 输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后
|
||||
* 一个拼音数字后没有空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 1234567890987654321123456789
|
||||
*
|
||||
* 输出样例:
|
||||
* yi san wu
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int sum = 0;
|
||||
char c, *pinyins[] = {"ling", "yi", "er", "san", "si",
|
||||
char c, *pinyins[] = {"ling", "yi", "er", "san", "si",
|
||||
"wu", "liu", "qi", "ba", "jiu"};
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
while((c = getchar()) != '\n')
|
||||
sum += c - '0';
|
||||
|
||||
|
||||
if(sum / 100) /* hundreds */
|
||||
printf("%s ", pinyins[sum / 100]);
|
||||
if(sum / 10) /* tens */
|
||||
printf("%s ", pinyins[sum / 10 % 10]);
|
||||
printf("%s", pinyins[sum % 10]); /* units */
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-49
@@ -1,45 +1,3 @@
|
||||
/**
|
||||
* 1003. 我要通过!
|
||||
* “答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送
|
||||
* —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。
|
||||
*
|
||||
* 得到“答案正确”的条件是:
|
||||
*
|
||||
* 1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;
|
||||
* 2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者
|
||||
* 是仅由字母 A 组成的字符串;
|
||||
* 3. 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a, b, c 均或者是空字符
|
||||
* 串,或者是仅由字母 A 组成的字符串。
|
||||
*
|
||||
* 现在就请你为PAT写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。
|
||||
* 输入格式: 每个测试输入包含1个测试用例。第1行给出一个自然数n (<10),是需要检测
|
||||
* 的字符串个数。接下来每个字符串占一行,字符串长度不超过100,且不包含空格。
|
||||
*
|
||||
* 输出格式:每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出
|
||||
* YES,否则输出NO。
|
||||
*
|
||||
* 输入样例:
|
||||
* 8
|
||||
* PAT
|
||||
* PAAT
|
||||
* AAPATAA
|
||||
* AAPAATAAAA
|
||||
* xPATx
|
||||
* PT
|
||||
* Whatever
|
||||
* APAAATAA
|
||||
*
|
||||
* 输出样例:
|
||||
* YES
|
||||
* YES
|
||||
* YES
|
||||
* YES
|
||||
* NO
|
||||
* NO
|
||||
* NO
|
||||
* NO
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -47,7 +5,7 @@ int main()
|
||||
char c;
|
||||
int num;
|
||||
scanf("%d", &num);
|
||||
while(getchar() != '\n'); /* read the rest of the line,
|
||||
while(getchar() != '\n'); /* read the rest of the line,
|
||||
make sure to start from a new line later */
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
@@ -61,19 +19,19 @@ int main()
|
||||
else if(c == 'T' && pos == 1) pos = 2; /* one T after P */
|
||||
else break; /* 'wrong' string */
|
||||
}
|
||||
|
||||
|
||||
if(c == '\n' /* 1. no other characters at end */
|
||||
&& pos == 2 /* 2. appearance of 'P' and 'T' */
|
||||
&& count[1] /* 3. existance of 'A' */
|
||||
&& count[2] == count[1] * count[0]) /* 4. relation between numbers */
|
||||
&& count[2] == count[1] * count[0]) /* 4. relation between numbers */
|
||||
puts("YES");
|
||||
else
|
||||
puts("NO");
|
||||
|
||||
|
||||
/* read the rest of the line */
|
||||
if(c != '\n')
|
||||
while(getchar() != '\n');
|
||||
if(c != '\n')
|
||||
while(getchar() != '\n');
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-36
@@ -1,33 +1,3 @@
|
||||
/**
|
||||
* 1004. 成绩排名
|
||||
*
|
||||
* 读入n名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。
|
||||
*
|
||||
* 输入格式:每个测试输入包含1个测试用例,格式为
|
||||
*
|
||||
* 第1行:正整数n
|
||||
* 第2行:第1个学生的姓名 学号 成绩
|
||||
* 第3行:第2个学生的姓名 学号 成绩
|
||||
* ... ... ...
|
||||
* 第n+1行:第n个学生的姓名 学号 成绩
|
||||
*
|
||||
* 其中姓名和学号均为不超过10个字符的字符串,成绩为0到100之间的一个整数,这里保证在
|
||||
* 一组测试用例中没有两个学生的成绩是相同的。
|
||||
*
|
||||
* 输出格式:对每个测试用例输出2行,第1行是成绩最高学生的姓名和学号,第2行是成绩最
|
||||
* 低学生的姓名和学号,字符串间有1空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3
|
||||
* Joe Math990112 89
|
||||
* Mike CS991301 100
|
||||
* Mary EE990830 95
|
||||
*
|
||||
* 输出样例:
|
||||
* Mike CS991301
|
||||
* Joe Math990112
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -35,15 +5,15 @@ int main()
|
||||
{
|
||||
int N;
|
||||
scanf("%d", &N);
|
||||
|
||||
char maxname[11], minname[11], curname[11],
|
||||
|
||||
char maxname[11], minname[11], curname[11],
|
||||
maxid[11], minid[11], curid[11];
|
||||
int maxgrade = -1, mingrade = 101, curgrade;
|
||||
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%s %s %d", curname, curid, &curgrade);
|
||||
|
||||
|
||||
if(curgrade > maxgrade)
|
||||
{
|
||||
strcpy(maxname, curname);
|
||||
@@ -57,8 +27,8 @@ int main()
|
||||
mingrade = curgrade;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("%s %s\n%s %s", maxname, maxid, minname, minid);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-35
@@ -1,53 +1,25 @@
|
||||
/**
|
||||
* 1005. 继续(3n+1)猜想
|
||||
*
|
||||
* 卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。
|
||||
*
|
||||
* 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。
|
||||
* 例如对n=3进行验证的时候,我们需要计算3、5、8、4、2、1,则当我们对n=5、8、4、2
|
||||
* 进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这4个数已经
|
||||
* 在验证3的时候遇到过了,我们称5、8、4、2是被3“覆盖”的数。我们称一个数列中的某个
|
||||
* 数n为“关键数”,如果n不能被数列中的其他数字所覆盖。
|
||||
*
|
||||
* 现在给定一系列待验证的数字,我们只需要验证其中的几个关键数,就可以不必再重复验证
|
||||
* 余下的数字。你的任务就是找出这些关键数字,并按从大到小的顺序输出它们。
|
||||
*
|
||||
* 输入格式:每个测试输入包含1个测试用例,第1行给出一个正整数K(<100),第2行给出K个
|
||||
* 互不相同的待验证的正整数n(1<n<=100)的值,数字间用空格隔开。
|
||||
*
|
||||
* 输出格式:每个测试用例的输出占一行,按从大到小的顺序输出关键数字。数字间用1个
|
||||
* 空格隔开,但一行中最后一个数字后没有空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 6
|
||||
* 3 5 6 7 8 11
|
||||
*
|
||||
* 输出样例:
|
||||
* 7 6
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int K, n, tabel[101] = {0};
|
||||
|
||||
|
||||
scanf("%d", &K);
|
||||
for(int i = 0; i < K; i++)
|
||||
{
|
||||
scanf("%d", &n);
|
||||
tabel[n] = 1;
|
||||
}
|
||||
|
||||
|
||||
/* find numbers needed to test */
|
||||
for(int i = 1; i <= 100; i++)
|
||||
for(int i = 1; i <= 100; i++)
|
||||
if(tabel[i])
|
||||
for(int j = i; j > 1; )
|
||||
{
|
||||
/* calculate for one step */
|
||||
if(j % 2) j = (3 * j + 1) / 2;
|
||||
else j /= 2;
|
||||
|
||||
|
||||
/* see if the new number is in given numbers */
|
||||
if(j <= 100 && tabel[j])
|
||||
{
|
||||
@@ -56,10 +28,10 @@ int main()
|
||||
if(j < i) break; /* did this before, no need going on */
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 100; i >= 1; i--)
|
||||
|
||||
for(int i = 100; i >= 1; i--)
|
||||
if(tabel[i] == 1)
|
||||
printf("%d%c", i, --K ? ' ' : '\0');
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,26 +1,3 @@
|
||||
/**
|
||||
* 1006. 换个格式输出整数
|
||||
* 让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个
|
||||
* 格式来输出任一个不超过3位的正整数。例如234应该被输出为BBSSS1234,因为它有2个
|
||||
* “百”、3个“十”、以及个位的4。
|
||||
*
|
||||
* 输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000)。
|
||||
*
|
||||
* 输出格式:每个测试用例的输出占一行,用规定的格式输出n。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 234
|
||||
*
|
||||
* 输出样例1:
|
||||
* BBSSS1234
|
||||
*
|
||||
* 输入样例2:
|
||||
* 23
|
||||
*
|
||||
* 输出样例2:
|
||||
* SS123
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
+5
-24
@@ -1,22 +1,3 @@
|
||||
/**
|
||||
* 1007. 素数对猜想
|
||||
*
|
||||
* 让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数。显然有 d1=1 且对于n>1有
|
||||
* dn 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。
|
||||
*
|
||||
* 现给定任意正整数N (< 10^5),请计算不超过N的满足猜想的素数对的个数。
|
||||
*
|
||||
* 输入格式:每个测试输入包含1个测试用例,给出正整数N。
|
||||
*
|
||||
* 输出格式:每个测试用例的输出占一行,不超过N的满足猜想的素数对的个数。
|
||||
*
|
||||
* 输入样例:
|
||||
* 20
|
||||
*
|
||||
* 输出样例:
|
||||
* 4
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -29,28 +10,28 @@ int main()
|
||||
int primes[100] = {2, 3}; /* Record the prime numbers before sqrt(10^5) */
|
||||
int twincount = 0; /* Count of twin primes */
|
||||
int primecount = 2; /* Count of prime numbers */
|
||||
|
||||
|
||||
/* Start from 4 */
|
||||
for(int i = 4; i <= N; i++)
|
||||
{
|
||||
/* Test if i is a prime number */
|
||||
iPrime = 1;
|
||||
for(int j = 0; iPrime && primes[j] * primes[j] <= i; j++)
|
||||
for(int j = 0; iPrime && primes[j] * primes[j] <= i; j++)
|
||||
if(i % primes[j] == 0)
|
||||
iPrime = 0;
|
||||
|
||||
|
||||
/* If i is a prime number, record */
|
||||
if(iPrime)
|
||||
{
|
||||
if(primecount < 100) primes[primecount++] = i;
|
||||
if(iPrimeMinus2 == 1) twincount++; /* a prime pair found */
|
||||
}
|
||||
|
||||
|
||||
/* Shift the primality flags to next numbers */
|
||||
iPrimeMinus2 = iPrimeMinus1;
|
||||
iPrimeMinus1 = iPrime;
|
||||
}
|
||||
printf("%d", twincount);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-24
@@ -1,25 +1,3 @@
|
||||
/**
|
||||
* 1008. 数组元素循环右移问题
|
||||
*
|
||||
* 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向
|
||||
* 右移M(M>=0)个位置,即将A中的数据由(A0 A1……AN-1)变换为
|
||||
* (AN-M …… AN-1 A0 A1……AN-M-1)(最后M个数循环移至最前面的M个位置)。如果需要
|
||||
* 考虑程序移动数据的次数尽量少,要如何设计移动的方法?
|
||||
*
|
||||
* 输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N<=100)、M(M>=0);第2行输
|
||||
* 入N个整数,之间用空格分隔。
|
||||
*
|
||||
* 输出格式:在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有
|
||||
* 多余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 6 2
|
||||
* 1 2 3 4 5 6
|
||||
*
|
||||
* 输出样例:
|
||||
* 5 6 1 2 3 4
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -32,13 +10,13 @@ int main()
|
||||
/* Read */
|
||||
for(int i = 0; i < N; i++)
|
||||
scanf("%d", &numbers[i]);
|
||||
|
||||
|
||||
/* Print */
|
||||
for(int i = N - M; i < N; i++) /* Print N - M to N - 1 */
|
||||
printf("%d ", numbers[i]);
|
||||
for(int i = 0; i < N - M - 1; i++) /* Print 0 to N - M - 2 */
|
||||
printf("%d ", numbers[i]);
|
||||
printf("%d", numbers[N - M - 1]); /* Print N - M - 1, no blankspace */
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-20
@@ -1,21 +1,3 @@
|
||||
/**
|
||||
* 1009. 说反话
|
||||
*
|
||||
* 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。
|
||||
*
|
||||
* 输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串
|
||||
* 由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,
|
||||
* 单词之间用1个空格分开,输入保证句子末尾没有多余的空格。
|
||||
*
|
||||
* 输出格式:每个测试用例的输出占一行,输出倒序后的句子。
|
||||
*
|
||||
* 输入样例:
|
||||
* Hello World Here I Come
|
||||
*
|
||||
* 输出样例:
|
||||
* Come I Here World Hello
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -23,12 +5,12 @@ int main()
|
||||
{
|
||||
char line[81], *p = line, *i;
|
||||
fgets(line, 81, stdin);
|
||||
|
||||
|
||||
while(*++p); /* Go to the end of the string */
|
||||
while(p > line) /* Will break at the beginning of the string */
|
||||
{
|
||||
while(isspace(*--p)) ; /* Find the end of a word */
|
||||
while(p > line && !isspace(*(p - 1))) p--; /* Find start of the word */
|
||||
while(p > line && !isspace(*(p - 1))) p--; /* Find start of the word */
|
||||
for(i = p; *i && !isspace(*i); putchar(*i++)); /* Print the word */
|
||||
putchar(p == line ? '\0' : ' '); /* print blankspace if not at end */
|
||||
}
|
||||
|
||||
+4
-22
@@ -1,28 +1,10 @@
|
||||
/**
|
||||
* 1010. 一元多项式求导
|
||||
*
|
||||
* 设计函数求一元多项式的导数。(注:x^n(n为整数)的一阶导数为n*x^n-1。)
|
||||
*
|
||||
* 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。
|
||||
* 数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但
|
||||
* 结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3 4 -5 2 6 1 -2 0
|
||||
*
|
||||
* 输出样例:
|
||||
* 12 3 -10 1 6 0
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int coef, index, count = 0;
|
||||
|
||||
while(scanf("%d %d", &coef, &index) != EOF)
|
||||
while(scanf("%d %d", &coef, &index) != EOF)
|
||||
{
|
||||
if(index) /* Constant terms result in zero */
|
||||
{
|
||||
@@ -30,10 +12,10 @@ int main()
|
||||
printf("%d %d", coef * index, index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Zero polynomial or constant */
|
||||
if(count == 0)
|
||||
if(count == 0)
|
||||
puts("0 0");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-31
@@ -1,32 +1,3 @@
|
||||
/**
|
||||
* 1011. A+B和C
|
||||
*
|
||||
* 给定区间[-2^31, 2^31]内的3个整数A、B和C,请判断A+B是否大于C。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第1行给出正整数T(<=10),是测试用例的个数。随后给出T组测试用例,每组占一行,
|
||||
* 顺序给出A、B和C。整数间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每组测试用例,在一行中输出“Case #X: true”如果A+B>C,否则输出
|
||||
* “Case #X: false”,其中X是测试用例的编号(从1开始)。
|
||||
*
|
||||
* 输入样例:
|
||||
* 4
|
||||
* 1 2 3
|
||||
* 2 3 4
|
||||
* 2147483647 0 2147483646
|
||||
* 0 -2147483648 -2147483647
|
||||
*
|
||||
* 输出样例:
|
||||
* Case #1: false
|
||||
* Case #2: true
|
||||
* Case #3: true
|
||||
* Case #4: false
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -34,12 +5,12 @@ int main()
|
||||
int T;
|
||||
long int A, B, C;
|
||||
scanf("%d", &T);
|
||||
|
||||
|
||||
for(int i = 0; i < T; i++)
|
||||
{
|
||||
scanf("%ld %ld %ld", &A, &B, &C);
|
||||
printf("Case #%d: %s\n", i + 1, A + B > C ? "true" : "false");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-38
@@ -1,39 +1,3 @@
|
||||
/**
|
||||
* 1012. 数字分类
|
||||
*
|
||||
* 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:
|
||||
*
|
||||
* A1 = 能被5整除的数字中所有偶数的和;
|
||||
* A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...;
|
||||
* A3 = 被5除后余2的数字的个数;
|
||||
* A4 = 被5除后余3的数字的平均数,精确到小数点后1位;
|
||||
* A5 = 被5除后余4的数字中最大数字。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例先给出一个不超过1000的正整数N,随后给出N个
|
||||
* 不超过1000的待分类的正整数。数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对给定的N个正整数,按题目要求计算A1~A5并在一行中顺序输出。数字间以空格分隔,但
|
||||
* 行末不得有多余空格。
|
||||
*
|
||||
* 若其中某一类数字不存在,则在相应位置输出“N”。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 13 1 2 3 4 5 6 7 8 9 10 20 16 18
|
||||
*
|
||||
* 输出样例1:
|
||||
* 30 11 2 9.7 9
|
||||
*
|
||||
* 输入样例2:
|
||||
* 8 1 2 4 5 6 7 9 16
|
||||
*
|
||||
* 输出样例2:
|
||||
* N 11 2 N 9
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -41,7 +5,7 @@ int main()
|
||||
int count;
|
||||
int A1 = 0, A2 = 0, A3 = 0, A4 = 0, A5 = 0;
|
||||
int A2flag = 0, A4count = 0;
|
||||
|
||||
|
||||
scanf("%d", &count);
|
||||
for(int i = 0, n; i < count; i++)
|
||||
{
|
||||
@@ -61,6 +25,6 @@ int main()
|
||||
if(A3 == 0) printf("N "); else printf("%d ", A3);
|
||||
if(A4 == 0) printf("N "); else printf("%.1f ", A4 * 1.0 / A4count);
|
||||
if(A5 == 0) printf("N"); else printf("%d", A5);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-28
@@ -1,34 +1,12 @@
|
||||
/**
|
||||
* 1013. 数素数 (20)
|
||||
*
|
||||
* 令P_i表示第i个素数。现任给两个正整数M <= N <= 10^4,请输出P_M到P_N的所有素数。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中给出M和N,其间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出从P_M到P_N的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 5 27
|
||||
*
|
||||
* 输出样例:
|
||||
* 11 13 17 19 23 29 31 37 41 43
|
||||
* 47 53 59 61 67 71 73 79 83 89
|
||||
* 97 101 103
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
int M, N;
|
||||
scanf("%d %d", &M, &N);
|
||||
int primes[10000];
|
||||
|
||||
|
||||
for(int n = 2, count = 0; count < N; n++)
|
||||
{
|
||||
/* Check if n is prime number */
|
||||
@@ -36,12 +14,12 @@ int main()
|
||||
for(int j = 0; count > 0 && primes[j] * primes[j] <= n; j++)
|
||||
if(n % primes[j] == 0)
|
||||
iprime = 0;
|
||||
|
||||
|
||||
/* Record */
|
||||
if(iprime)
|
||||
if(iprime)
|
||||
primes[count++] = n;
|
||||
}
|
||||
|
||||
|
||||
/* Print */
|
||||
for(int i = M; i < N; i++)
|
||||
{
|
||||
@@ -49,6 +27,6 @@ int main()
|
||||
printf((i - M + 1) % 10 ? " " : "\n");
|
||||
}
|
||||
printf("%d", primes[N - 1]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-38
@@ -1,37 +1,3 @@
|
||||
/**
|
||||
* 1014. 福尔摩斯的约会 (20)
|
||||
*
|
||||
* 大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧!
|
||||
* 3485djDkxh4hhGE
|
||||
* 2984akDfkkkkggEdsb
|
||||
* s&hgsfdk
|
||||
* d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间
|
||||
* “星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)
|
||||
* 是第4个字母'D',代表星期四;第2对相同的字符是'E',那是第5个英文字母,代表
|
||||
* 一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);
|
||||
* 后面两字符串第1对相同的英文字母's'出现在第4个位置(从0开始计数)上,代表
|
||||
* 第4分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即
|
||||
* MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期四,FRI表示星期五,
|
||||
* SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3485djDkxh4hhGE
|
||||
* 2984akDfkkkkggEdsb
|
||||
* s&hgsfdk
|
||||
* d&Hyscvnm
|
||||
*
|
||||
* 输出样例:
|
||||
* THU 14:04
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -39,7 +5,7 @@ int main()
|
||||
{
|
||||
char str1[61], str2[61], str3[61], str4[61];
|
||||
scanf("%s %s %s %s", str1, str2, str3, str4);
|
||||
|
||||
|
||||
/* Find day, same char from [A-G] and same position in frist two lines */
|
||||
int DAY;
|
||||
char *weekdays[] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
|
||||
@@ -49,7 +15,7 @@ int main()
|
||||
printf("%s", weekdays[str1[DAY] - 'A']);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Find hour, picking up from DAY, same character and position, [A-N|0-9] */
|
||||
int HH;
|
||||
for(HH = DAY + 1; str1[HH] && str2[HH]; HH++)
|
||||
@@ -66,7 +32,7 @@ int main()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Find minute, same alphabet character from last two lines */
|
||||
int MM;
|
||||
for(MM = 0; str3[MM] && str4[MM]; MM++)
|
||||
@@ -75,6 +41,6 @@ int main()
|
||||
printf(":%02d", MM);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-64
@@ -1,62 +1,3 @@
|
||||
/**
|
||||
* 1015. 德才论 (25)
|
||||
*
|
||||
* 宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,
|
||||
* 才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子
|
||||
* 而与之,与其得小人,不若得愚人。”
|
||||
*
|
||||
* 现给出一批考生的德才分数,请根据司马光的理论给出录取排名。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第1行给出3个正整数,分别为:N(<=10^5),即考生总数;L(>=60),为录取最低
|
||||
* 分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线
|
||||
* ——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;
|
||||
* 才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;
|
||||
* 德才分均低于H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分
|
||||
* 排序,但排在第二类考生之后;其他达到最低线L的考生也按总分排序,但排在第三类考生之后。
|
||||
*
|
||||
* 随后N行,每行给出一位考生的信息,包括:准考证号、德分、才分,其中准考证号为8位
|
||||
* 整数,德才分为区间[0, 100]内的整数。数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行按照输入格式输出一位
|
||||
* 考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按
|
||||
* 其德分降序排列;若德分也并列,则按准考证号的升序输出。
|
||||
*
|
||||
* 输入样例:
|
||||
* 14 60 80
|
||||
* 10000001 64 90
|
||||
* 10000002 90 60
|
||||
* 10000011 85 80
|
||||
* 10000003 85 80
|
||||
* 10000004 80 85
|
||||
* 10000005 82 77
|
||||
* 10000006 83 76
|
||||
* 10000007 90 78
|
||||
* 10000008 75 79
|
||||
* 10000009 59 90
|
||||
* 10000010 88 45
|
||||
* 10000012 80 100
|
||||
* 10000013 90 99
|
||||
* 10000014 66 60
|
||||
* 输出样例:
|
||||
* 12
|
||||
* 10000013 90 99
|
||||
* 10000012 80 100
|
||||
* 10000003 85 80
|
||||
* 10000011 85 80
|
||||
* 10000004 80 85
|
||||
* 10000007 90 78
|
||||
* 10000006 83 76
|
||||
* 10000005 82 77
|
||||
* 10000002 90 60
|
||||
* 10000014 66 60
|
||||
* 10000008 75 79
|
||||
* 10000001 64 90
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -82,7 +23,7 @@ int comp(const void *a, const void *b)
|
||||
{
|
||||
Student s1 = *(Student*)a;
|
||||
Student s2 = *(Student*)b;
|
||||
|
||||
|
||||
if(s1->rank != s2->rank) return s1->rank - s2->rank;
|
||||
else if(s1->sum != s2->sum) return s1->sum - s2->sum;
|
||||
else if(s1->D != s2->D) return s1->D - s2->D;
|
||||
@@ -95,22 +36,22 @@ int main()
|
||||
int N, L, H, M = 0;
|
||||
Student students[100000] = {0};
|
||||
sStudent buffer[100000];
|
||||
|
||||
|
||||
scanf("%d %d %d", &N, &L, &H);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
Student s = buffer + i;
|
||||
scanf("%d %d %d", &s->ID, &s->D, &s->C);
|
||||
scanf("%d %d %d", &s->ID, &s->D, &s->C);
|
||||
s->sum = s->D + s->C;
|
||||
if((s->rank = rank(s, H, L)) != 0) /* record if passed */
|
||||
students[M++] = s;
|
||||
}
|
||||
|
||||
qsort(students, M, sizeof(Student), comp);
|
||||
|
||||
|
||||
printf("%d\n", M);
|
||||
for(int i = M - 1; i >= 0; i--)
|
||||
printf("%d %d %d\n", students[i]->ID, students[i]->D, students[i]->C);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-27
@@ -1,29 +1,3 @@
|
||||
/**
|
||||
* 1016. 部分A+B (15)
|
||||
*
|
||||
* 正整数A的“D_A(为1位整数)部分”定义为由A中所有D_A组成的新整数P_A。例如:给定
|
||||
* A = 3862767,D_A = 6,则A的“6部分”P_A是66,因为A中有2个6。
|
||||
*
|
||||
* 现给定A、D_A、B、D_B,请编写程序计算P_A + P_B。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中依次给出A、D_A、B、D_B,中间以空格分隔,其中0 < A, B < 10^10。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出P_A + P_B的值。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 3862767 6 13530293 3
|
||||
* 输出样例1:
|
||||
* 399
|
||||
* 输入样例2:
|
||||
* 3862767 1 13530293 8
|
||||
* 输出样例2:
|
||||
* 0
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
long Dpart(long A, int D_A)
|
||||
@@ -41,6 +15,6 @@ int main()
|
||||
int D_A, D_B;
|
||||
scanf("%ld %d %ld %d", &A, &D_A, &B, &D_B);
|
||||
printf("%ld", Dpart(A, D_A) + Dpart(B, D_B));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-23
@@ -1,23 +1,3 @@
|
||||
/**
|
||||
* 1017. A除以B (20)
|
||||
*
|
||||
* 本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和
|
||||
* 余数R,使得A = B * Q + R成立。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在1行中依次给出A和B,中间以1空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在1行中依次输出Q和R,中间以1空格分隔。
|
||||
*
|
||||
* 输入样例:
|
||||
* 123456789050987654321 7
|
||||
* 输出样例:
|
||||
* 17636684150141093474 3
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* read 2 digits from highest digit of A, do manual division, get the quotient
|
||||
@@ -29,7 +9,7 @@ int main()
|
||||
int B;
|
||||
char A[1001], *p = A;
|
||||
scanf("%s %d", A, &B);
|
||||
|
||||
|
||||
/* the results are stored in A and B instead of printed out on-the-fly */
|
||||
int twodigit, remainder = 0;
|
||||
for(int i = 0; A[i]; i ++)
|
||||
@@ -39,10 +19,10 @@ int main()
|
||||
remainder = twodigit % B;
|
||||
}
|
||||
B = remainder;
|
||||
|
||||
|
||||
/* print */
|
||||
if(A[0] == '0' && A[1] != '\0') p++;
|
||||
printf("%s %d", p, B);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-43
@@ -1,44 +1,3 @@
|
||||
/**
|
||||
* 1018. 锤子剪刀布 (20)
|
||||
*
|
||||
*
|
||||
* 大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:
|
||||
*
|
||||
* 图略
|
||||
*
|
||||
* 现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的
|
||||
* 胜算最大。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,
|
||||
* 即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表
|
||||
* 甲方,第2个代表乙方,中间有1个空格。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字
|
||||
* 母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯一,则输出按字母序
|
||||
* 最小的解。
|
||||
*
|
||||
* 输入样例:
|
||||
* 10
|
||||
* C J
|
||||
* J B
|
||||
* C B
|
||||
* B B
|
||||
* B C
|
||||
* C C
|
||||
* C B
|
||||
* J B
|
||||
* B C
|
||||
* J J
|
||||
* 输出样例:
|
||||
* 5 3 2
|
||||
* 2 3 5
|
||||
* B B
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char max(int B, int C, int J)
|
||||
@@ -54,7 +13,7 @@ int main()
|
||||
char a, b;
|
||||
int AwinB = 0, AwinC = 0, AwinJ = 0;
|
||||
int BwinB = 0, BwinC = 0, BwinJ = 0;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -66,7 +25,7 @@ int main()
|
||||
if(a == 'C' && b == 'B') BwinB++;
|
||||
if(a == 'J' && b == 'C') BwinC++;
|
||||
}
|
||||
|
||||
|
||||
int Awin = AwinB + AwinC + AwinJ;
|
||||
int Bwin = BwinB + BwinC + BwinJ;
|
||||
int Tie = N - Awin - Bwin;
|
||||
|
||||
+3
-43
@@ -1,47 +1,7 @@
|
||||
/**
|
||||
* 1019. 数字黑洞 (20)
|
||||
*
|
||||
* 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非
|
||||
* 递减排序,然后用第1个数字减第2个数字,将得到一个新的数字。一直重复这样做,我们
|
||||
* 很快会停在有“数字黑洞”之称的6174,这个神奇的数字也叫Kaprekar常数。
|
||||
*
|
||||
* 例如,我们从6767开始,将得到
|
||||
*
|
||||
* 7766 - 6677 = 1089
|
||||
* 9810 - 0189 = 9621
|
||||
* 9621 - 1269 = 8352
|
||||
* 8532 - 2358 = 6174
|
||||
* 7641 - 1467 = 6174
|
||||
* ... ...
|
||||
*
|
||||
* 现给定任意4位正整数,请编写程序演示到达黑洞的过程。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入给出一个(0, 10000)区间内的正整数N。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 如果N的4位数字全相等,则在一行内输出“N - N = 0000”;否则将计算的每一步在一行内
|
||||
* 输出,直到6174作为差出现,输出格式见样例。注意每个数字按4位数格式输出。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 6767
|
||||
* 输出样例1:
|
||||
* 7766 - 6677 = 1089
|
||||
* 9810 - 0189 = 9621
|
||||
* 9621 - 1269 = 8352
|
||||
* 8532 - 2358 = 6174
|
||||
* 输入样例2:
|
||||
* 2222
|
||||
* 输出样例2:
|
||||
* 2222 - 2222 = 0000
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int cmp(const void *a, const void *b)
|
||||
int cmp(const void *a, const void *b)
|
||||
{
|
||||
return *(int*)b - *(int*)a;
|
||||
}
|
||||
@@ -61,7 +21,7 @@ int reverse(int n)
|
||||
int main()
|
||||
{
|
||||
int N;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
do
|
||||
{
|
||||
@@ -69,6 +29,6 @@ int main()
|
||||
printf("%04d - %04d = %04d\n", N, reverse(N), N - reverse(N));
|
||||
N = N - reverse(N);
|
||||
}while(N != 0 && N != 6174) ;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-37
@@ -1,58 +1,28 @@
|
||||
/**
|
||||
* 1020. 月饼 (25)
|
||||
*
|
||||
* 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有
|
||||
* 种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。
|
||||
*
|
||||
* 注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有3种月饼,其库
|
||||
* 存量分别为18、15、10万吨,总售价分别为75、72、45亿元。如果市场的最大需求量只有
|
||||
* 20万吨,那么我们最大收益策略应该是卖出全部15万吨第2种月饼、以及5万吨第3种月饼,
|
||||
* 获得 72 + 45/2 = 94.5(亿元)。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例先给出一个不超过1000的正整数N表示月饼的种类
|
||||
* 数、以及不超过500(以万吨为单位)的正整数D表示市场最大需求量。随后一行给出N个正数
|
||||
* 表示每种月饼的库存量(以万吨为单位);最后一行给出N个正数表示每种月饼的总售价
|
||||
* (以亿元为单位)。数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每组测试用例,在一行中输出最大收益,以亿元为单位并精确到小数点后2位。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3 20
|
||||
* 18 15 10
|
||||
* 75 72 45
|
||||
* 输出样例:
|
||||
* 94.50
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, max;
|
||||
float D, Storage[1000], Total = 0, Price[1000];
|
||||
|
||||
float D, Storage[1000], Total = 0, Price[1000];
|
||||
|
||||
scanf("%d %f", &N, &D);
|
||||
for(int i = 0; i < N; i++) scanf("%f", Storage + i);
|
||||
for(int i = 0; i < N; i++) scanf("%f", Price + i);
|
||||
|
||||
|
||||
while(D > 0)
|
||||
{
|
||||
max = 0;
|
||||
for(int i = 0; i < N; i++)
|
||||
if(Price[i] / Storage[i] > Price[max] / Storage[max])
|
||||
max = i;
|
||||
|
||||
if(Storage[max] < D)
|
||||
|
||||
if(Storage[max] < D)
|
||||
{
|
||||
Total += Price[max];
|
||||
D -= Storage[max];
|
||||
Price[max] = 0;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
Total += Price[max] * D / Storage[max];
|
||||
D = 0;
|
||||
|
||||
+2
-27
@@ -1,28 +1,3 @@
|
||||
/**
|
||||
* 1021. 个位数统计 (15)
|
||||
*
|
||||
* 给定一个k位整数N = d_k-1*10^k-1 + ... + d_1*10^1 + d0 (0<=d_i<=9, i=0,...,k-1,
|
||||
* d_k-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,
|
||||
* 则有2个0,3个1,和1个3。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例,即一个不超过1000位的正整数N。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中出现的次数M。
|
||||
* 要求按D的升序输出。
|
||||
*
|
||||
* 输入样例:
|
||||
* 100311
|
||||
* 输出样例:
|
||||
*
|
||||
* 0:2
|
||||
* 1:3
|
||||
* 3:1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -31,9 +6,9 @@ int main()
|
||||
int count[10] = {0};
|
||||
while((c = getchar()) != '\n')
|
||||
count[c - '0']++;
|
||||
|
||||
|
||||
for(int i = 0; i < 10; i++) if(count[i])
|
||||
printf("%d:%d\n", i, count[i]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-22
@@ -1,22 +1,3 @@
|
||||
/**
|
||||
* 1022. D进制的A+B (20)
|
||||
*
|
||||
* 输入两个非负10进制整数A和B(<=2^30-1),输出A+B的D (1 < D <= 10)进制数。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中依次给出3个整数A、B和D。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出A+B的D进制数。
|
||||
*
|
||||
* 输入样例:
|
||||
* 123 456 8
|
||||
* 输出样例:
|
||||
* 1103
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -24,15 +5,15 @@ int main()
|
||||
int A, B, D, Sum;
|
||||
scanf("%d %d %d", &A, &B, &D);
|
||||
Sum = A + B;
|
||||
|
||||
|
||||
/* calculate the bits of Sum */
|
||||
int power = 1;
|
||||
/* use Sum / D >= power to avoid using long int */
|
||||
while(Sum / D >= power) power *= D;
|
||||
|
||||
|
||||
/* calculate D-base number. print them on-the-fly */
|
||||
for(; power > 0; Sum %= power, power /= D)
|
||||
printf("%d", Sum / power);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-27
@@ -1,34 +1,9 @@
|
||||
/**
|
||||
* 1023. 组个最小数 (20)
|
||||
*
|
||||
* 给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后
|
||||
* 得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们
|
||||
* 得到的最小的数就是10015558。
|
||||
*
|
||||
* 现给定数字,请编写程序输出能够组成的最小的数。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有
|
||||
* 数字0、数字1、……数字9的个数。整数间用一个空格分隔。10个数字的总个数不超过50,且
|
||||
* 至少拥有1个非0的数字。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出能够组成的最小的数。
|
||||
*
|
||||
* 输入样例:
|
||||
* 2 2 0 0 0 3 0 0 1 0
|
||||
* 输出样例:
|
||||
* 10015558
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int zero, nonzero;
|
||||
|
||||
|
||||
scanf("%d", &zero);
|
||||
for(int i = 1; i < 10; i++)
|
||||
{
|
||||
@@ -40,6 +15,6 @@ int main()
|
||||
putchar('0');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-31
@@ -1,33 +1,3 @@
|
||||
/**
|
||||
* 1024. 科学计数法 (20)
|
||||
*
|
||||
* 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式
|
||||
* [+-][1-9]"."[0-9]+E[+-][0-9]+,即数字的整数部分只有1位,小数部分至少有1位,
|
||||
* 该数字及其指数部分的正负号即使对正数也必定明确给出。
|
||||
*
|
||||
* 现以科学计数法的格式给出实数A,请编写程序按普通数字表示法输出A,并保证所有有效位
|
||||
* 都被保留。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例,即一个以科学计数法表示的实数A。该数字的存储长度不超过
|
||||
* 9999字节,且其指数的绝对值不超过9999。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每个测试用例,在一行中按普通数字表示法输出A,并保证所有有效位都被保留,
|
||||
* 包括末尾的0。
|
||||
*
|
||||
* 输入样例1:
|
||||
* +1.23400E-03
|
||||
* 输出样例1:
|
||||
* 0.00123400
|
||||
* 输入样例2:
|
||||
* -1.2E+10
|
||||
* 输出样例2:
|
||||
* -12000000000
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -55,6 +25,6 @@ int main()
|
||||
putchar('0');
|
||||
for(; *p; p++) if(*p != '.') putchar(*p); /* the rest */
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-43
@@ -1,42 +1,3 @@
|
||||
/**
|
||||
* 1025. 反转链表 (25)
|
||||
*
|
||||
* 给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为
|
||||
* 1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为
|
||||
* 4→3→2→1→5→6,即最后不到K个元素不反转。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址、结点总个数
|
||||
* 正整数N(<= 105)、以及正整数K(<=N),即要求反转的子链结点的个数。结点的地址是
|
||||
* 5位非负整数,NULL地址用-1表示。
|
||||
*
|
||||
* 接下来有N行,每行格式为:
|
||||
* Address Data Next
|
||||
*
|
||||
* 其中Address是结点地址,Data是该结点保存的整数数据,Next是下一结点的地址。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每个测试用例,顺序输出反转后的链表,其上每个结点占一行,格式与输入相同。
|
||||
*
|
||||
* 输入样例:
|
||||
* 00100 6 4
|
||||
* 00000 4 99999
|
||||
* 00100 1 12309
|
||||
* 68237 6 -1
|
||||
* 33218 3 00000
|
||||
* 99999 5 68237
|
||||
* 12309 2 33218
|
||||
* 输出样例:
|
||||
* 00000 4 33218
|
||||
* 33218 3 12309
|
||||
* 12309 2 00100
|
||||
* 00100 1 99999
|
||||
* 99999 5 68237
|
||||
* 68237 6 -1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -53,15 +14,15 @@ int main()
|
||||
int A, N, K;
|
||||
node nodes[100000] = {0};
|
||||
Node np[100000] = {0}, *p;
|
||||
|
||||
|
||||
/* read */
|
||||
scanf("%d %d %d", &A, &N, &K);
|
||||
for(int i = 0; i < N; i++)
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
np[i] = nodes + i;
|
||||
scanf("%d %d %d", &np[i]->addr, &np[i]->data, &np[i]->next);
|
||||
}
|
||||
|
||||
|
||||
/* link the list */
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -82,7 +43,7 @@ int main()
|
||||
for(int j = 0; j < K / 2; j++)
|
||||
SWAPNODE(p[j], p[K - j - 1]);
|
||||
}
|
||||
|
||||
|
||||
/* print the list */
|
||||
for(int i = 0; i < N - 1; i++)
|
||||
printf("%05d %d %05d\n", np[i]->addr, np[i]->data, np[i + 1]->addr);
|
||||
|
||||
@@ -1,33 +1,3 @@
|
||||
/**
|
||||
* 1026. 程序运行时间(15)
|
||||
*
|
||||
* 要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()
|
||||
* 函数,可以捕捉从程序开始运行到clock()被调用时所耗费的时间。这个时间单位是
|
||||
* clock tick,即“时钟打点”。同时还有一个常数CLK_TCK,给出了机器时钟每秒所走的时钟
|
||||
* 打点数。于是为了获得一个函数f的运行时间,我们只要在调用f之前先调用clock(),获得一
|
||||
* 个时钟打点数C1;在f执行完成后再调用clock(),获得另一个时钟打点数C2;两次获得的
|
||||
* 时钟打点数之差(C2-C1)就是f运行所消耗的时钟打点数,再除以常数CLK_TCK,就得到了以
|
||||
* 秒为单位的运行时间。
|
||||
*
|
||||
* 这里不妨简单假设常数CLK_TCK为100。现给定被测函数前后两次获得的时钟打点数,请你给
|
||||
* 出被测函数运行的时间。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中顺序给出2个整数C1和C2。注意两次获得的时钟打点数肯定不相同,即C1 < C2,
|
||||
* 并且取值在[0, 10^7]。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出被测函数运行的时间。运行时间必须按照“hh:mm:ss”(即2位的“时:分:秒”)
|
||||
* 格式输出;不足1秒的时间四舍五入到秒。
|
||||
*
|
||||
* 输入样例:
|
||||
* 123 4577973
|
||||
* 输出样例:
|
||||
* 12:42:59
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
@@ -1,37 +1,3 @@
|
||||
/**
|
||||
* 1027. 打印沙漏(20)
|
||||
*
|
||||
* 本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印
|
||||
*
|
||||
* *****
|
||||
* ***
|
||||
* *
|
||||
* ***
|
||||
* *****
|
||||
* 所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号
|
||||
* 数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。
|
||||
*
|
||||
* 给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行给出1个正整数N(<=1000)和一个符号,中间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
* 首先打印出由给定符号组成的最大的沙漏形状,最后在一行中输出剩下没用掉的符号数。
|
||||
*
|
||||
*
|
||||
* 输入样例:
|
||||
* 19 *
|
||||
* 输出样例:
|
||||
* *****
|
||||
* ***
|
||||
* *
|
||||
* ***
|
||||
* *****
|
||||
* 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define ABS(X) ((X) >= 0 ? (X) : -(X))
|
||||
|
||||
+6
-36
@@ -1,33 +1,3 @@
|
||||
/**
|
||||
* 1028. 人口普查(20)
|
||||
*
|
||||
* 某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。
|
||||
*
|
||||
* 这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的
|
||||
* 老人,而今天是2014年9月6日,所以超过200岁的生日和未出生的生日都是不合理的,应该
|
||||
* 被过滤掉。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出正整数N,取值在(0, 10^5];随后N行,每行给出1个人的姓名(由不超过
|
||||
* 5个英文字母组成的字符串)、以及按“yyyy/mm/dd”(即年/月/日)格式给出的生日。题目
|
||||
* 保证最年长和最年轻的人没有并列。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中顺序输出有效生日的个数、最年长人和最年轻人的姓名,其间以空格分隔。
|
||||
*
|
||||
* 输入样例:
|
||||
* 5
|
||||
* John 2001/05/12
|
||||
* Tom 1814/09/06
|
||||
* Ann 2121/01/30
|
||||
* James 1814/09/05
|
||||
* Steve 1967/11/20
|
||||
* 输出样例:
|
||||
* 3 Tom John
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -36,25 +6,25 @@ int main()
|
||||
int N, count = 0;
|
||||
/* store name and birthday in one string: "YYYY/MM/DD\0NAMES\0" */
|
||||
char cur[17], eldest[17] = {'9'}, youngest[17] = {'0'};
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%s %s", cur + 11, cur);
|
||||
if(strcmp(cur, "1814/09/06") >= 0 && strcmp(cur, "2014/09/06") <= 0)
|
||||
if(strcmp(cur, "1814/09/06") >= 0 && strcmp(cur, "2014/09/06") <= 0)
|
||||
{
|
||||
if(strcmp(cur, eldest) <= 0)
|
||||
if(strcmp(cur, eldest) <= 0)
|
||||
memcpy(eldest, cur, 17);
|
||||
if(strcmp(cur, youngest) >= 0)
|
||||
memcpy(youngest, cur, 17);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(count)
|
||||
printf("%d %s %s", count, eldest + 11, youngest + 11);
|
||||
else
|
||||
else
|
||||
printf("0");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-25
@@ -1,27 +1,3 @@
|
||||
/**
|
||||
* 1029. 旧键盘(20)
|
||||
*
|
||||
* 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该
|
||||
* 输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符
|
||||
* 的串,由字母A-Z(包括大、小写)、数字0-9、以及下划线“_”(代表空格)组成。题目保证
|
||||
* 2个字符串均非空。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。
|
||||
* 题目保证至少有1个坏键。
|
||||
*
|
||||
* 输入样例:
|
||||
* 7_This_is_a_test
|
||||
* _hs_s_a_es
|
||||
* 输出样例:
|
||||
* 7TI
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -34,7 +10,7 @@ int main()
|
||||
while((c = getchar()) != '\n')
|
||||
printed[toupper(c)]++;
|
||||
|
||||
for(char *p = line; *p; p++)
|
||||
for(char *p = line; *p; p++)
|
||||
{
|
||||
c = toupper(*p);
|
||||
if(printed[(int)c] == 0)
|
||||
|
||||
+7
-30
@@ -1,50 +1,27 @@
|
||||
/**
|
||||
* 1030. 完美数列(25)
|
||||
*
|
||||
* 给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果
|
||||
* M <= m * p,则称这个数列是完美数列。
|
||||
*
|
||||
* 现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出两个正整数N和p,其中N(<= 105)是输入的正整数的个数,p(<= 109)
|
||||
* 是给定的参数。第二行给出N个正整数,每个数不超过109。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出最多可以选择多少个数可以用它们组成一个完美数列。
|
||||
* 输入样例:
|
||||
* 10 8
|
||||
* 2 3 20 4 5 1 6 7 8 9
|
||||
* 输出样例:
|
||||
* 8
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int comp(const void *a, const void *b)
|
||||
{
|
||||
return *(int*)a - *(int*)b;
|
||||
int comp(const void *a, const void *b)
|
||||
{
|
||||
return *(int*)a - *(int*)b;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, p, data[100000];
|
||||
int max = 0, first, last;
|
||||
|
||||
|
||||
scanf("%d %d", &N, &p); /* read */
|
||||
for(int i = 0; i < N; i++)
|
||||
for(int i = 0; i < N; i++)
|
||||
scanf("%d", data + i);
|
||||
|
||||
|
||||
qsort(data, N, sizeof(int), comp); /* sort */
|
||||
|
||||
for(first = 0, last = 0; last < N && max < N - first; first++) /* find */
|
||||
{
|
||||
while(last < N && data[last] <= 1L * data[first] * p)
|
||||
last++;
|
||||
if(max < last - first)
|
||||
if(max < last - first)
|
||||
max = last - first;
|
||||
}
|
||||
printf("%d", max);
|
||||
|
||||
+4
-47
@@ -1,46 +1,3 @@
|
||||
/**
|
||||
* 1031. 查验身份证(15)
|
||||
*
|
||||
* 一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算
|
||||
* 规则如下:
|
||||
*
|
||||
* 首先对前17位数字加权求和,权重分配为:
|
||||
* {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得
|
||||
* 到值Z;最后按照以下关系对应Z值与校验码M的值:
|
||||
*
|
||||
* Z:0 1 2 3 4 5 6 7 8 9 10
|
||||
* M:1 0 X 9 8 7 6 5 4 3 2
|
||||
*
|
||||
* 现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出正整数N(<= 100)是输入的身份证号码的个数。随后N行,每行给出1个18位
|
||||
* 身份证号码。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 按照输入的顺序每行输出1个有问题的身份证号码。这里并不检验前17位是否合理,只检查
|
||||
* 前17位是否全为数字且最后1位校验码计算准确。如果所有号码都正常,则输出“All passed”。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 4
|
||||
* 320124198808240056
|
||||
* 12010X198901011234
|
||||
* 110108196711301866
|
||||
* 37070419881216001X
|
||||
* 输出样例1:
|
||||
* 12010X198901011234
|
||||
* 110108196711301866
|
||||
* 37070419881216001X
|
||||
* 输入样例2:
|
||||
* 2
|
||||
* 320124198808240056
|
||||
* 110108196711301862
|
||||
* 输出样例2:
|
||||
* All passed
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -49,16 +6,16 @@ int main()
|
||||
int weight[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
|
||||
char ZtoM[] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
|
||||
char ID[19];
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
int d, sum, count = 0; /* index, weighted sum and count for legal IDs */
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%s", ID);
|
||||
|
||||
|
||||
for(d = 0, sum = 0; d < 17 && ID[d] >= '0' && ID[d] <= '9'; d++)
|
||||
sum += (ID[d] - '0') * weight[d];
|
||||
|
||||
|
||||
if(d == 17 && ID[17] == ZtoM[sum % 11]) /* legal ID */
|
||||
count++;
|
||||
else /* illegal ID */
|
||||
@@ -66,6 +23,6 @@ int main()
|
||||
}
|
||||
if(count == N)
|
||||
puts("All passed");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-34
@@ -1,51 +1,22 @@
|
||||
/**
|
||||
* 1032. 挖掘机技术哪家强(20)
|
||||
*
|
||||
* 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛。现请你根据比赛
|
||||
* 结果统计出技术最强的那个学校。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第1行给出不超过105的正整数N,即参赛人数。随后N行,每行给出一位参赛者的信息
|
||||
* 和成绩,包括其所代表的学校的编号(从1开始连续编号)、及其比赛成绩(百分制),中间
|
||||
* 以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,
|
||||
* 没有并列。
|
||||
*
|
||||
* 输入样例:
|
||||
* 6
|
||||
* 3 65
|
||||
* 2 80
|
||||
* 1 100
|
||||
* 2 70
|
||||
* 3 40
|
||||
* 3 0
|
||||
* 输出样例:
|
||||
* 2 150
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, iSchool, score, imax = 0;
|
||||
scanf("%d", &N);
|
||||
|
||||
|
||||
int schools[100000] = {0};
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%d %d", &iSchool, &score);
|
||||
schools[iSchool - 1] += score;
|
||||
}
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
if(schools[i] > schools[imax])
|
||||
imax = i;
|
||||
|
||||
|
||||
printf("%d %d", imax + 1, schools[imax]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-29
@@ -1,29 +1,3 @@
|
||||
/**
|
||||
* 1033. 旧键盘打字(20)
|
||||
*
|
||||
* 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该
|
||||
* 输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写
|
||||
* 给出;每段文字是不超过105个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及
|
||||
* 下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保证第2行输入的文字
|
||||
* 串非空。
|
||||
*
|
||||
* 注意:如果上档键坏掉了,那么大写的英文字母无法被打出。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。
|
||||
*
|
||||
* 输入样例:
|
||||
* 7+IE.
|
||||
* 7_This_is_a_test.
|
||||
* 输出样例:
|
||||
* _hs_s_a_tst
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -31,13 +5,13 @@ int main()
|
||||
{
|
||||
char c;
|
||||
int bad[128] = {0}; /* record keys are broken or not */
|
||||
|
||||
|
||||
while((c = getchar()) != '\n') /* read broken keys */
|
||||
bad[toupper(c)] = 1;
|
||||
|
||||
|
||||
while((c = getchar()) != '\n') /* read string and print */
|
||||
if(!bad[toupper(c)] && !(isupper(c) && bad['+']))
|
||||
putchar(c);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-40
@@ -1,36 +1,3 @@
|
||||
/**
|
||||
* 1034. 有理数四则运算(20)
|
||||
*
|
||||
* 本题要求编写程序,计算2个有理数的和、差、积、商。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是
|
||||
* 整型范围内的整数,负号只可能出现在分子前,分母不为0。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 分别在4行中按照“有理数1 运算符 有理数2 = 结果”的格式顺序输出2个有理数的和、差、
|
||||
* 积、商。注意输出的每个有理数必须是该有理数的最简形式“k a/b”,其中k是整数部分,
|
||||
* a/b是最简分数部分;若为负数,则须加括号;若除法分母为0,则输出“Inf”。题目保证正
|
||||
* 确的输出中没有超过整型范围的整数。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 2/3 -4/2
|
||||
* 输出样例1:
|
||||
* 2/3 + (-2) = (-1 1/3)
|
||||
* 2/3 - (-2) = 2 2/3
|
||||
* 2/3 * (-2) = (-1 1/3)
|
||||
* 2/3 / (-2) = (-1/3)
|
||||
* 输入样例2:
|
||||
* 5/3 0/6
|
||||
* 输出样例2:
|
||||
* 1 2/3 + 0 = 1 2/3
|
||||
* 1 2/3 - 0 = 1 2/3
|
||||
* 1 2/3 * 0 = 0
|
||||
* 1 2/3 / 0 = Inf
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Both parameters take positive value */
|
||||
@@ -49,17 +16,17 @@ long calcgcd(long a, long b)
|
||||
void printfrac(long n, long d)
|
||||
{
|
||||
if(d == 0) { printf("Inf"); return; }
|
||||
|
||||
|
||||
/* record the sign and make them positive */
|
||||
int inegative = 1;
|
||||
int inegative = 1;
|
||||
if(n < 0) { n = -n; inegative *= -1; }
|
||||
if(d < 0) { d = -d; inegative *= -1; }
|
||||
|
||||
|
||||
/* reduce the fraction */
|
||||
long gcd = calcgcd(n, d);
|
||||
long gcd = calcgcd(n, d);
|
||||
n /= gcd;
|
||||
d /= gcd;
|
||||
|
||||
|
||||
/* print */
|
||||
if(inegative == -1) printf("(-");
|
||||
if(n / d && n % d) printf("%ld %ld/%ld", n / d, n % d, d); /* mixed fractions */
|
||||
@@ -72,7 +39,7 @@ int main()
|
||||
{
|
||||
long a1, b1, a2, b2;
|
||||
scanf("%ld/%ld %ld/%ld", &a1, &b1, &a2, &b2);
|
||||
|
||||
|
||||
char op[4] = {'+', '-', '*', '/'};
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
@@ -87,6 +54,6 @@ int main()
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-45
@@ -1,46 +1,8 @@
|
||||
/**
|
||||
* 1035. 插入与归并(25)
|
||||
*
|
||||
* 根据维基百科的定义:
|
||||
*
|
||||
* 插入排序是迭代算法,逐一获得输入数据,逐步产生有序的输出序列。每步迭代中,算法从
|
||||
* 输入序列中取出一元素,将之插入有序序列中正确的位置。如此迭代直到全部元素有序。
|
||||
*
|
||||
* 归并排序进行如下迭代操作:首先将原始序列看成N个只包含1个元素的有序子序列,然后每
|
||||
* 次迭代归并两个相邻的有序子序列,直到最后只剩下1个有序的序列。
|
||||
*
|
||||
* 现给定原始序列和由某排序算法产生的中间序列,请你判断该算法究竟是哪种排序算法?
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出正整数N (<=100);随后一行给出原始序列的N个整数;最后一行给出由某
|
||||
* 排序算法产生的中间序列。这里假设排序的目标序列是升序。数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
* 首先在第1行中输出“Insertion Sort”表示插入排序、或“Merge Sort”表示归并排序;然后
|
||||
* 在第2行中输出用该排序算法再迭代一轮的结果序列。题目保证每组测试的结果是唯一的。
|
||||
* 数字间以空格分隔,且行末不得有多余空格。
|
||||
* 输入样例1:
|
||||
* 10
|
||||
* 3 1 2 8 7 5 9 4 6 0
|
||||
* 1 2 3 7 8 5 9 4 6 0
|
||||
* 输出样例1:
|
||||
* Insertion Sort
|
||||
* 1 2 3 5 7 8 9 4 6 0
|
||||
* 输入样例2:
|
||||
* 10
|
||||
* 3 1 2 8 7 5 9 4 0 6
|
||||
* 1 3 2 8 5 7 4 9 0 6
|
||||
* 输出样例2:
|
||||
* Merge Sort
|
||||
* 1 2 3 8 4 5 7 9 0 6
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int comp(const void *a, const void *b)
|
||||
{
|
||||
{
|
||||
return *(int*)a - *(int*)b;
|
||||
}
|
||||
|
||||
@@ -50,12 +12,12 @@ int main()
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++) scanf("%d", origin + i);
|
||||
for(int i = 0; i < N; i++) scanf("%d", halfsort + i);
|
||||
|
||||
|
||||
/* if it is insertion sort, return sorted length if yes, zero otherwise */
|
||||
for(i = 0; i < N - 1 && halfsort[i] <= halfsort[i + 1]; i++) ;
|
||||
for(length = ++i; i < N && halfsort[i] == origin[i]; i++) ;
|
||||
length = i == N ? length + 1 : 0;
|
||||
|
||||
|
||||
if(length) /* insertion sort */
|
||||
{
|
||||
puts("Insertion Sort");
|
||||
@@ -67,15 +29,15 @@ int main()
|
||||
for(length = 1, i = 0; i < N && length <= N; length *= 2)
|
||||
{
|
||||
/* i == N means identical, also breaks the outer 'for' loop */
|
||||
for(i = 0; i < N && origin[i] == halfsort[i]; i++) ;
|
||||
for(i = 0; i < N && origin[i] == halfsort[i]; i++) ;
|
||||
for(j = 0; j < N / length; j++)
|
||||
qsort(origin + j * length, length, sizeof(int), comp);
|
||||
qsort(origin + j * length, N % length, sizeof(int), comp);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
printf("%d%c", origin[i], i == N - 1 ? '\n' : ' ');
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-26
@@ -1,27 +1,3 @@
|
||||
/**
|
||||
* 美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位
|
||||
* 编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很
|
||||
* 简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中给出正方形边长N(3<=N<=20)和组成正方形边的某种字符C,间隔一个空格。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出由给定字符C画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像
|
||||
* 正方形,我们输出的行数实际上是列数的50%(四舍五入取整)。
|
||||
*
|
||||
* 输入样例:
|
||||
* 10 a
|
||||
* 输出样例:
|
||||
* aaaaaaaaaa
|
||||
* a a
|
||||
* a a
|
||||
* a a
|
||||
* aaaaaaaaaa
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -29,7 +5,7 @@ int main()
|
||||
int N;
|
||||
char c;
|
||||
scanf("%d %c", &N, &c);
|
||||
|
||||
|
||||
for(int i = 0; i < (N + 1) / 2; i++)
|
||||
{
|
||||
for(int j = 0; j < N; j++)
|
||||
@@ -41,6 +17,6 @@ int main()
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-31
@@ -1,45 +1,17 @@
|
||||
/**
|
||||
* 1037. 在霍格沃茨找零钱(20)
|
||||
*
|
||||
* 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:
|
||||
* “十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”
|
||||
* 现在,给定哈利应付的价钱P和他实付的钱A,你的任务是写一个程序来计算他应该被找的零钱。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在1行中分别给出P和A,格式为“Galleon.Sickle.Knut”,其间用1个空格分隔。这里
|
||||
* Galleon是[0, 107]区间内的整数,Sickle是[0, 17)区间内的整数,Knut是[0, 29)区间内
|
||||
* 的整数。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中用与输入同样的格式输出哈利应该被找的零钱。如果他没带够钱,那么输出的应该
|
||||
* 是负数。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 10.16.27 14.1.28
|
||||
* 输出样例1:
|
||||
* 3.2.1
|
||||
* 输入样例2:
|
||||
* 14.1.28 10.16.27
|
||||
* 输出样例2:
|
||||
* -3.2.1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Galleon, Sickle, Knut, P, A, change;
|
||||
|
||||
|
||||
scanf("%d.%d.%d", &Galleon, &Sickle, &Knut);
|
||||
P = (Galleon * 17 + Sickle) * 29 + Knut;
|
||||
scanf("%d.%d.%d", &Galleon, &Sickle, &Knut);
|
||||
A = (Galleon * 17 + Sickle) * 29 + Knut;
|
||||
|
||||
|
||||
change = A - P;
|
||||
if(change < 0) { change = -change; putchar('-'); }
|
||||
printf("%d.%d.%d", change / (17 * 29), change / 29 % 17, change % 29);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-27
@@ -1,46 +1,22 @@
|
||||
/**
|
||||
* 1038. 统计同成绩学生(20)
|
||||
*
|
||||
* 本题要求读入N名学生的成绩,将获得某一给定分数的学生人数输出。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第1行给出不超过10^5的正整数N,即学生总人数。随后1行给出N名学生的百分制整数
|
||||
* 成绩,中间以空格分隔。最后1行给出要查询的分数个数K(不超过N的正整数),随后是K个
|
||||
* 分数,中间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中按查询顺序给出得分等于指定分数的学生人数,中间以空格分隔,但行末不得有多
|
||||
* 余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 10
|
||||
* 60 75 90 55 75 99 82 90 75 50
|
||||
* 3 75 90 88
|
||||
* 输出样例:
|
||||
* 3 2 0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, M, score, count[101] = {0};
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%d", &score);
|
||||
count[score]++;
|
||||
}
|
||||
|
||||
|
||||
scanf("%d", &M);
|
||||
for(int i = 0; i < M; i++)
|
||||
{
|
||||
scanf("%d", &score);
|
||||
printf("%d%c", count[score], i == M - 1 ? '\n' : ' ');
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-38
@@ -1,38 +1,3 @@
|
||||
/**
|
||||
* 1039. 到底买不买(20)
|
||||
*
|
||||
* 小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯
|
||||
* 把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠
|
||||
* 子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。
|
||||
*
|
||||
* 为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如在图1中,第3串
|
||||
* 是小红想做的珠串;那么第1串可以买,因为包含了全部她想要的珠子,还多了8颗不需要的
|
||||
* 珠子;第2串不能买,因为没有黑色珠子,并且少了一颗红色的珠子。
|
||||
*
|
||||
* 图 1
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例分别在2行中先后给出摊主的珠串和小红想做的珠
|
||||
* 串,两串都不超过1000个珠子。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 如果可以买,则在一行中输出“Yes”以及有多少多余的珠子;如果不可以买,则在一行中输
|
||||
* 出“No”以及缺了多少珠子。其间以1个空格分隔。
|
||||
*
|
||||
* 输入样例1:
|
||||
* ppRYYGrrYBR2258
|
||||
* YrR8RrY
|
||||
* 输出样例1:
|
||||
* Yes 8
|
||||
* 输入样例2:
|
||||
* ppRYYGrrYB225
|
||||
* YrR8RrY
|
||||
* 输出样例2:
|
||||
* No 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -41,16 +6,16 @@ int main()
|
||||
int record[128] = {0}; /* all ASCII characters */
|
||||
while((c = getchar()) != '\n') record[(int)c]++;
|
||||
while((c = getchar()) != '\n') record[(int)c]--;
|
||||
|
||||
|
||||
int more = 0, less = 0;
|
||||
for(int i = 0; i < 128; i++)
|
||||
{
|
||||
if(record[i] > 0) more += record[i];
|
||||
if(record[i] < 0) less -= record[i];
|
||||
}
|
||||
|
||||
|
||||
if(less) printf("No %d", less);
|
||||
else printf("Yes %d", more);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-25
@@ -1,26 +1,3 @@
|
||||
/**
|
||||
* 1040. 有几个PAT(25)
|
||||
*
|
||||
* 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T);
|
||||
* 第二个PAT是第3位(P),第4位(A),第6位(T)。
|
||||
*
|
||||
* 现给定字符串,问一共可以形成多少个PAT?
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入只有一行,包含一个字符串,长度不超过10^5,只包含P、A、T三种字母。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出给定字符串中包含多少个PAT。由于结果可能比较大,只输出对1000000007取
|
||||
* 余数的结果。
|
||||
*
|
||||
* 输入样例:
|
||||
* APPAPT
|
||||
* 输出样例:
|
||||
* 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define LIM 1000000007
|
||||
@@ -29,7 +6,7 @@ int main()
|
||||
{
|
||||
int P = 0, PA = 0, PAT = 0;
|
||||
char c;
|
||||
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
{
|
||||
if(c == 'P') P++;
|
||||
@@ -37,6 +14,6 @@ int main()
|
||||
if(c == 'T') PAT = (PAT + PA) % LIM;
|
||||
}
|
||||
printf("%d", PAT);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-38
@@ -1,38 +1,3 @@
|
||||
/**
|
||||
* 1041. 考试座位号(15)
|
||||
*
|
||||
* 每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常
|
||||
* 情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考
|
||||
* 试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们
|
||||
* 只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数N(<=1000),随后N行,每行给出一个考生的信息:
|
||||
* “准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成,座位从1到N编号。
|
||||
* 输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。
|
||||
*
|
||||
* 考生信息之后,给出一个正整数M(<=N),随后一行中给出M个待查询的试机座位号码,
|
||||
* 以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,
|
||||
* 中间用1个空格分隔。
|
||||
*
|
||||
* 输入样例:
|
||||
* 4
|
||||
* 10120150912233 2 4
|
||||
* 10120150912119 4 1
|
||||
* 10120150912126 1 3
|
||||
* 10120150912002 3 2
|
||||
* 2
|
||||
* 3 4
|
||||
* 输出样例:
|
||||
* 10120150912002 2
|
||||
* 10120150912119 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -47,7 +12,7 @@ int main()
|
||||
int N, M, test;
|
||||
Student students[1001] = {0}; /* N >= 1000 */
|
||||
pStudent sp[1001] = {0};
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -55,13 +20,13 @@ int main()
|
||||
scanf("%s %d %d", s->ID, &s->test_seat, &s->exam_seat);
|
||||
sp[s->test_seat] = s; /* set index same as test number */
|
||||
}
|
||||
|
||||
|
||||
scanf("%d", &M);
|
||||
for(int i = 0; i < M; i ++)
|
||||
{
|
||||
scanf("%d", &test);
|
||||
printf("%s %d\n", sp[test]->ID, sp[test]->exam_seat);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-26
@@ -1,24 +1,3 @@
|
||||
/**
|
||||
* 1042. 字符统计(20)
|
||||
*
|
||||
* 请编写程序,找出一段给定文字中出现最频繁的那个英文字母。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中给出一个长度不超过1000的字符串。字符串由ASCII码表中任意可见字符及空
|
||||
* 格组成,至少包含1个英文字母,以回车结束(回车不算在内)。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔。如果有并列,
|
||||
* 则输出按字母序最小的那个字母。统计时不区分大小写,输出小写字母。
|
||||
*
|
||||
* 输入样例:
|
||||
* This is a simple TEST. There ARE numbers and other symbols 1&2&3...........
|
||||
* 输出样例:
|
||||
* e 7
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -26,16 +5,16 @@ int main()
|
||||
{
|
||||
char c;
|
||||
int count[26] = {0}, max = 25;
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
if(isalpha(c))
|
||||
count[tolower(c) - 'a']++;
|
||||
|
||||
|
||||
/* find forward from end in case there are multiple maximums */
|
||||
for(int i = 25; i >= 0; i--)
|
||||
for(int i = 25; i >= 0; i--)
|
||||
if(count[i] >= count[max])
|
||||
max = i;
|
||||
|
||||
|
||||
printf("%c %d", max + 'a', count[max]);
|
||||
|
||||
return 0;
|
||||
|
||||
+4
-26
@@ -1,41 +1,19 @@
|
||||
/**
|
||||
* 1043. 输出PATest(20)
|
||||
*
|
||||
* 给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按
|
||||
* “PATestPATest....”这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是
|
||||
* 一样多的,若某种字符已经输出完,则余下的字符仍按PATest的顺序打印,直到所有字符都
|
||||
* 被输出。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中按题目要求输出排序后的字符串。题目保证输出非空。
|
||||
*
|
||||
* 输入样例:
|
||||
* redlesPayBestPATTopTeePHPereatitAPPT
|
||||
* 输出样例:
|
||||
* PATestPATestPTetPTePePee
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c, *str = "PATest"; /* use as index for count[] */
|
||||
int i, flag = 1, count[128] = {0}; /* for each ASCII char */
|
||||
|
||||
|
||||
/* Read and count numbers for every character */
|
||||
while((c = getchar()) != '\n')
|
||||
count[(int)c]++;
|
||||
|
||||
|
||||
/* Print any character in "PATest" if it is still left */
|
||||
while(flag)
|
||||
for(i = 0, flag = 0; i < 6; i++)
|
||||
for(i = 0, flag = 0; i < 6; i++)
|
||||
if(count[(int)str[i]]-- > 0) /* Check the number left */
|
||||
putchar(str[i]), flag = 1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-40
@@ -1,46 +1,10 @@
|
||||
/**
|
||||
* 1044. 火星数字(20)
|
||||
*
|
||||
* 火星人是以13进制计数的:
|
||||
*
|
||||
* 地球人的0被火星人称为tret。
|
||||
* 地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep,
|
||||
* oct, nov, dec。
|
||||
* 火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo,
|
||||
* syy, lok, mer, jou。
|
||||
*
|
||||
* 例如地球人的数字“29”翻译成火星文就是“hel mar”;而火星文“elo nov”对应地球数字
|
||||
* “115”。为了方便交流,请你编写程序实现地球和火星数字之间的互译。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数N(<100),随后N行,每行给出一个[0, 169)区间内的数字 ——
|
||||
* 或者是地球文,或者是火星文。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对应输入的每一行,在一行中输出翻译后的另一种语言的数字。
|
||||
*
|
||||
* 输入样例:
|
||||
* 4
|
||||
* 29
|
||||
* 5
|
||||
* elo nov
|
||||
* tam
|
||||
* 输出样例:
|
||||
* hel mar
|
||||
* may
|
||||
* 115
|
||||
* 13
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char *units[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly",
|
||||
char *units[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly",
|
||||
"aug", "sep", "oct", "nov", "dec"};
|
||||
char *tens[] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo",
|
||||
char *tens[] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo",
|
||||
"syy", "lok", "mer", "jou"};
|
||||
|
||||
int Mars2Earth(char *s)
|
||||
@@ -61,7 +25,7 @@ int main()
|
||||
{
|
||||
int N, m;
|
||||
char line[11];
|
||||
|
||||
|
||||
fgets(line, 11, stdin);
|
||||
sscanf(line, "%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
@@ -84,6 +48,6 @@ int main()
|
||||
printf("%d\n", m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-38
@@ -1,53 +1,20 @@
|
||||
/**
|
||||
* 1045. 快速排序(25)
|
||||
*
|
||||
* 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,
|
||||
* 通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。 给定划分后的
|
||||
* N个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元?
|
||||
*
|
||||
* 例如给定N = 5, 排列是1、3、2、4、5。则:
|
||||
*
|
||||
* 1的左边没有元素,右边的元素都比它大,所以它可能是主元;
|
||||
* 尽管3的左边元素都比它小,但是它右边的2它小,所以它不能是主元;
|
||||
* 尽管2的右边元素都比它大,但其左边的3比它大,所以它不能是主元;
|
||||
* 类似原因,4和5都可能是主元。
|
||||
* 因此,有3个元素可能是主元。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第1行中给出一个正整数N(<= 105); 第2行是空格分隔的N个不同的正整数,每个数
|
||||
* 不超过109。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在第1行中输出有可能是主元的元素个数;在第2行中按递增顺序输出这些元素,其间以1个空
|
||||
* 格分隔,行末不得有多余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 5
|
||||
* 1 3 2 4 5
|
||||
* 输出样例:
|
||||
* 3
|
||||
* 1 4 5
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, count = 0;
|
||||
int array[100000], lmax[100000], rmin[100000];
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++) scanf("%d", array + i);
|
||||
|
||||
|
||||
/* Find the largest on one's left and the smallest on the right */
|
||||
for(int i = 0, max = i; i < N; i++)
|
||||
lmax[i] = array[i] >= array[max] ? array[max = i] : array[max];
|
||||
for(int i = N - 1, min = i; i >= 0; i--)
|
||||
rmin[i] = array[i] <= array[min] ? array[min = i] : array[min];
|
||||
|
||||
/* A element is the largest on its left and the smallest on its right,
|
||||
|
||||
/* A element is the largest on its left and the smallest on its right,
|
||||
* it is probably a pivot */
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -61,6 +28,6 @@ int main()
|
||||
for(int i = 0; i < N && count; i++) if(array[i])
|
||||
printf("%d%c", array[i], --count ? ' ' : '\0');
|
||||
printf("\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,35 +1,3 @@
|
||||
/**
|
||||
* 1046. 划拳(15)
|
||||
*
|
||||
* 划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一
|
||||
* 个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就
|
||||
* 赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。
|
||||
*
|
||||
* 下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行先给出一个正整数N(<=100),随后N行,每行给出一轮划拳的记录,格式为:
|
||||
*
|
||||
* 甲喊 甲划 乙喊 乙划
|
||||
*
|
||||
* 其中“喊”是喊出的数字,“划”是划出的数字,均为不超过100的正整数(两只手一起划)。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中先后输出甲、乙两人喝酒的杯数,其间以一个空格分隔。
|
||||
* 输入样例:
|
||||
*
|
||||
* 5
|
||||
* 8 10 9 12
|
||||
* 5 10 5 10
|
||||
* 3 8 5 12
|
||||
* 12 18 1 13
|
||||
* 4 16 12 15
|
||||
* 输出样例:
|
||||
* 1 2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
+2
-32
@@ -1,39 +1,9 @@
|
||||
/**
|
||||
* 1047. 编程团体赛(20)
|
||||
*
|
||||
* 编程团体赛的规则为:每个参赛队由若干队员组成;所有队员独立比赛;参赛队的成绩为所
|
||||
* 有队员的成绩和;成绩最高的队获胜。
|
||||
*
|
||||
* 现给定所有队员的比赛成绩,请你编写程序找出冠军队。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数N(<=10000),即所有参赛队员总数。随后N行,每行给出一位
|
||||
* 队员的成绩,格式为:“队伍编号-队员编号 成绩”,其中“队伍编号”为1到1000的正整数,
|
||||
* “队员编号”为1到10的正整数,“成绩”为0到100的整数。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出冠军队的编号和总成绩,其间以一个空格分隔。注意:题目保证冠军队是唯一的。
|
||||
*
|
||||
* 输入样例:
|
||||
* 6
|
||||
* 3-10 99
|
||||
* 11-5 87
|
||||
* 102-1 0
|
||||
* 102-3 100
|
||||
* 11-9 89
|
||||
* 3-2 61
|
||||
* 输出样例:
|
||||
* 11 176
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, team, member, score, highest = 0, teams[1000] = {0};
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -44,6 +14,6 @@ int main()
|
||||
if(teams[i] > teams[highest])
|
||||
highest = i;
|
||||
printf("%d %d", highest + 1, teams[highest]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-24
@@ -1,25 +1,3 @@
|
||||
/**
|
||||
* 1048. 数字加密(20)
|
||||
*
|
||||
* 本题要求实现一种数字加密方法。首先固定一个加密用正整数A,对任一正整数B,将其每1位
|
||||
* 数字与A的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对13取余——这里
|
||||
* 用J代表10、Q代表11、K代表12;对偶数位,用B的数字减去A的数字,若结果为负数,则再
|
||||
* 加10。这里令个位为第1位。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中依次给出A和B,均为不超过100位的正整数,其间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出加密后的结果。
|
||||
*
|
||||
* 输入样例:
|
||||
* 1234567 368782971
|
||||
* 输出样例:
|
||||
* 3695Q8118
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -33,12 +11,12 @@ int main()
|
||||
int lenB = strlen(B);
|
||||
int maxlen = lenA > lenB ? lenA : lenB;
|
||||
int a, b;
|
||||
|
||||
|
||||
for(int i = 0; i < maxlen; i++)
|
||||
{
|
||||
a = lenA + i - maxlen < 0 ? 0 : A[lenA + i - maxlen] - '0';
|
||||
b = lenB + i - maxlen < 0 ? 0 : B[lenB + i - maxlen] - '0';
|
||||
|
||||
|
||||
if((maxlen - i) % 2)
|
||||
putchar(encrypt[(a + b) % 13]);
|
||||
else
|
||||
|
||||
+2
-28
@@ -1,36 +1,10 @@
|
||||
/**
|
||||
* 1049. 数列的片段和(20)
|
||||
*
|
||||
* 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段。例如,给定数列
|
||||
* {0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3,
|
||||
* 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0.4) 这10个片段。
|
||||
*
|
||||
* 给定正整数数列,求出全部片段包含的所有的数之和。如本例中10个片段总和是0.1 + 0.3 +
|
||||
* 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个不超过105的正整数N,表示数列中数的个数,第二行给出N个不超过1.0
|
||||
* 的正数,是数列中的数,其间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出该序列所有片段包含的数之和,精确到小数点后2位。
|
||||
*
|
||||
* 输入样例:
|
||||
* 4
|
||||
* 0.1 0.2 0.3 0.4
|
||||
* 输出样例:
|
||||
* 5.00
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N;
|
||||
double ai, sum = 0;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -39,6 +13,6 @@ int main()
|
||||
sum += ai * (i + 1) * (N - i);
|
||||
}
|
||||
printf("%.2lf", sum);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-33
@@ -1,33 +1,7 @@
|
||||
/**
|
||||
* 1050. 螺旋矩阵(25)
|
||||
*
|
||||
* 本题要求将给定的N个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左
|
||||
* 上角第1个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为m行n列,满足条件:m*n等
|
||||
* 于N;m>=n;且m-n取所有可能值中的最小值。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第1行中给出一个正整数N,第2行给出N个待填充的正整数。所有数字不超过104,相邻
|
||||
* 数字以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出螺旋矩阵。每行n个数字,共m行。相邻数字以1个空格分隔,行末不得有多余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 12
|
||||
* 37 76 20 98 76 42 53 95 60 81 58 93
|
||||
* 输出样例:
|
||||
* 98 95 93
|
||||
* 42 37 81
|
||||
* 53 20 76
|
||||
* 58 60 76
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int cmp(const void *a, const void *b)
|
||||
int cmp(const void *a, const void *b)
|
||||
{
|
||||
return *(int*)b - *(int*)a;
|
||||
}
|
||||
@@ -36,20 +10,20 @@ int main()
|
||||
{
|
||||
int N, m, n;
|
||||
int array[10000] = {0}, matrix[10000] = {0};
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
scanf("%d", array + i);
|
||||
|
||||
qsort(array, N, sizeof(int), cmp);
|
||||
|
||||
|
||||
/* determine m and n */
|
||||
for(m = 1; !(m * m >= N && N % m == 0); m++) ;
|
||||
n = N / m;
|
||||
|
||||
|
||||
int x = -1, y = 0, index = 0;
|
||||
int horizontal = n, virtical = m;
|
||||
|
||||
|
||||
while(horizontal > 0 && virtical > 0)
|
||||
{
|
||||
for(int i = 0; i < horizontal && virtical > 0; i++) /* toward right */
|
||||
@@ -68,10 +42,10 @@ int main()
|
||||
matrix[--y * n + x] = array[index++];
|
||||
horizontal--;
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < m; i++)
|
||||
for(int j = 0; j < n; j++)
|
||||
printf("%d%c", matrix[i * n + j], j == n - 1 ? '\n' : ' ');
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-28
@@ -1,27 +1,3 @@
|
||||
/**
|
||||
* 1051. 复数乘法 (15)
|
||||
*
|
||||
* 复数可以写成(A + Bi)的常规形式,其中A是实部,B是虚部,i是虚数单位,满足i2 = -1;
|
||||
* 也可以写成极坐标下的指数形式(R*e(Pi)),其中R是复数模,P是辐角,i是虚数单位,其等价
|
||||
* 于三角形式 R(cos(P) + isin(P))。
|
||||
*
|
||||
* 现给定两个复数的R和P,要求输出两数乘积的常规形式。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中依次给出两个复数的R1, P1, R2, P2,数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中按照“A+Bi”的格式输出两数乘积的常规形式,实部和虚部均保留2位小数。注意:
|
||||
* 如果B是负数,则应该写成“A-|B|i”的形式。
|
||||
*
|
||||
* 输入样例:
|
||||
* 2.3 3.5 5.2 0.4
|
||||
* 输出样例:
|
||||
* -8.68-8.23i
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
@@ -29,15 +5,15 @@ int main()
|
||||
{
|
||||
double R1, P1, R2, P2; /* float type won't pass, not sure why */
|
||||
double A, B;
|
||||
|
||||
|
||||
scanf("%lf %lf %lf %lf", &R1, &P1, &R2, &P2);
|
||||
A = R1 * R2 * cos(P1 + P2); /* doesn't matter how you calculate */
|
||||
B = R1 * R2 * sin(P1 + P2);
|
||||
|
||||
|
||||
if(A < 0 && A > -0.005) A = 0; /* Rounding */
|
||||
if(B < 0 && B > -0.005) B = 0;
|
||||
|
||||
|
||||
printf("%.2lf%+.2lfi", A, B);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-41
@@ -1,42 +1,3 @@
|
||||
/**
|
||||
* 1052. 卖个萌 (20)
|
||||
*
|
||||
* 萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情
|
||||
* 符号是按下列格式输出的:
|
||||
*
|
||||
* [左手]([左眼][口][右眼])[右手]
|
||||
* 现给出可选用的符号集合,请你按用户的要求输出表情。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号[]内。
|
||||
* 题目保证每个集合都至少有一个符号,并不超过10个符号;每个符号包含1到4个非空字符。
|
||||
*
|
||||
* 之后一行给出一个正整数K,为用户请求的个数。随后K行,每行给出一个用户的符号选择,
|
||||
* 顺序为左手、左眼、口、右眼、右手——这里只给出符号在相应集合中的序号(从1开始),
|
||||
* 数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每个用户请求,在一行中输出生成的表情。若用户选择的序号不存在,则输出
|
||||
* “Are you kidding me? @\/@”。
|
||||
*
|
||||
* 输入样例:
|
||||
* [╮][╭][o][~\][/~] [<][>]
|
||||
* [╯][╰][^][-][=][>][<][@][⊙]
|
||||
* [Д][▽][_][ε][^] ...
|
||||
* 4
|
||||
* 1 1 2 2 2
|
||||
* 6 8 1 5 5
|
||||
* 3 3 4 3 3
|
||||
* 2 10 3 9 3
|
||||
* 输出样例:
|
||||
* ╮(╯▽╰)╭
|
||||
* <(@Д=)/~
|
||||
* o(^ε^)o
|
||||
* Are you kidding me? @\/@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* About special characters, see:
|
||||
@@ -50,7 +11,7 @@ int main()
|
||||
for(int symbol = 0; symbol < 3; symbol++)
|
||||
for(int index = 0; (c = getchar()) != '\n'; )
|
||||
if(c == '[') scanf("%[^]]", symbols[symbol][index++]);
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -65,6 +26,6 @@ int main()
|
||||
else
|
||||
puts("Are you kidding me? @\\/@");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-40
@@ -1,40 +1,3 @@
|
||||
/**
|
||||
* 1053. 住房空置率 (20)
|
||||
*
|
||||
* 在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行
|
||||
* 判断。判断方法如下:
|
||||
*
|
||||
* 在观察期内,若存在超过一半的日子用电量低于某给定的阈值e,则该住房为“可能空置”;
|
||||
* 若观察期超过某给定阈值D天,且满足上一个条件,则该住房为“空置”。
|
||||
* 现给定某居民区的住户用电量数据,请你统计“可能空置”的比率和“空置”比率,即以上两种
|
||||
* 状态的住房占居民区住房总套数的百分比。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出正整数N(<=1000),为居民区住房总套数;正实数e,即低电量阈值;正整
|
||||
* 数D,即观察期阈值。随后N行,每行按以下格式给出一套住房的用电量数据:
|
||||
*
|
||||
* K E1 E2 ... EK
|
||||
*
|
||||
* 其中K为观察的天数,Ei为第i天的用电量。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出“可能空置”的比率和“空置”比率的百分比值,其间以一个空格分隔,保留小数
|
||||
* 点后1位。
|
||||
*
|
||||
* 输入样例:
|
||||
* 5 0.5 10
|
||||
* 6 0.3 0.4 0.5 0.2 0.8 0.6
|
||||
* 10 0.0 0.1 0.2 0.3 0.0 0.8 0.6 0.7 0.0 0.5
|
||||
* 5 0.4 0.3 0.5 0.1 0.7
|
||||
* 11 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
|
||||
* 11 2 2 2 1 1 0.1 1 0.1 0.1 0.1 0.1
|
||||
* 输出样例:
|
||||
* 40.0% 20.0%
|
||||
* (样例解释:第2、3户为“可能空置”,第4户为“空置”,其他户不是空置。)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -42,7 +5,7 @@ int main()
|
||||
int N, D, K;
|
||||
int empty = 0, pempty = 0, lower;
|
||||
float e, E;
|
||||
|
||||
|
||||
scanf("%d %f %d", &N, &e, &D);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -54,9 +17,9 @@ int main()
|
||||
if(E < e) lower++;
|
||||
}
|
||||
if(lower > K / 2 && K > D) empty++;
|
||||
else if(lower > K / 2) pempty++;
|
||||
else if(lower > K / 2) pempty++;
|
||||
}
|
||||
printf("%.1f%% %.1f%%", 100.0 * pempty / N, 100.0 * empty / N);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-41
@@ -1,39 +1,3 @@
|
||||
/**
|
||||
* 1054. 求平均值 (20)
|
||||
*
|
||||
* 本题的基本要求非常简单:给定N个实数,计算它们的平均值。但复杂的是有些输入数据可能
|
||||
* 是非法的。一个“合法”的输入是[-1000,1000]区间内的实数,并且最多精确到小数点后2位。
|
||||
* 当你计算平均值的时候,不能把那些非法的数据算在内。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出正整数N(<=100)。随后一行给出N个实数,数字间以一个空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每个非法输入,在一行中输出“ERROR: X is not a legal number”,其中X是输入。最后
|
||||
* 在一行中输出结果:“The average of K numbers is Y”,其中K是合法输入的个数,Y是它
|
||||
* 们的平均值,精确到小数点后2位。如果平均值无法计算,则用“Undefined”替换Y。如果K为
|
||||
* 1,则输出“The average of 1 number is Y”。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 7
|
||||
* 5 -3.2 aaa 9999 2.3.4 7.123 2.35
|
||||
* 输出样例1:
|
||||
* ERROR: aaa is not a legal number
|
||||
* ERROR: 9999 is not a legal number
|
||||
* ERROR: 2.3.4 is not a legal number
|
||||
* ERROR: 7.123 is not a legal number
|
||||
* The average of 3 numbers is 1.38
|
||||
* 输入样例2:
|
||||
* 2
|
||||
* aaa -9999
|
||||
* 输出样例2:
|
||||
* ERROR: aaa is not a legal number
|
||||
* ERROR: -9999 is not a legal number
|
||||
* The average of 0 numbers is Undefined
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -45,16 +9,16 @@ int main()
|
||||
double f, sum = 0;
|
||||
/* Maxium scenario: -1000.00. So just need to read 8 chars(+ '\0' = 9) */
|
||||
char s[9], *pEnd, *pDot, c;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%8s", s); /* Just read up to 8 chars */
|
||||
|
||||
|
||||
c = ungetc(getchar(), stdin); /* Read next char and push back */
|
||||
f = strtod(s, &pEnd); /* pEnd -> converted floating number */
|
||||
pDot = strchr(s, '.'); /* pDot -> (first) decimal point */
|
||||
|
||||
|
||||
if(!isspace(c) /* string too long */
|
||||
|| *pEnd /* not floating number */
|
||||
|| (f > 1000 || f < -1000) /* out of range */
|
||||
@@ -71,10 +35,10 @@ int main()
|
||||
sum += f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(count == 0) printf("The average of 0 numbers is Undefined\n");
|
||||
if(count == 1) printf("The average of 1 number is %.2lf", sum);
|
||||
if(count >= 2) printf("The average of %d numbers is %.2lf", count, sum / count);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-45
@@ -1,44 +1,3 @@
|
||||
/**
|
||||
* 拍集体照时队形很重要,这里对给定的N个人K排的队形设计排队规则如下:
|
||||
*
|
||||
* 每排人数为N/K(向下取整),多出来的人全部站在最后一排;
|
||||
* 后排所有人的个子都不比前排任何人矮;
|
||||
* 每排中最高者站中间(中间位置为m/2+1,其中m为该排人数,除法向下取整);
|
||||
* 每排其他人以中间人为轴,按身高非增序,先右后左交替入队站在中间人的两侧(例如5人身
|
||||
* 高为190、188、186、175、170,则队形为175、188、190、186、170。这里假设你面对拍
|
||||
* 照者,所以你的左边是中间人的右边);
|
||||
* 若多人身高相同,则按名字的字典序升序排列。这里保证无重名。
|
||||
* 现给定一组拍照人,请编写程序输出他们的队形。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例第1行给出两个正整数N(<=10000,总人数)和K
|
||||
* (<=10,总排数)。随后N行,每行给出一个人的名字(不包含空格、长度不超过8个英文字母)
|
||||
* 和身高([30, 300]区间内的整数)。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出拍照的队形。即K排人名,其间以空格分隔,行末不得有多余空格。注意:假设你面对
|
||||
* 拍照者,后排的人输出在上方,前排输出在下方。
|
||||
*
|
||||
* 输入样例:
|
||||
* 10 3
|
||||
* Tom 188
|
||||
* Mike 170
|
||||
* Eva 168
|
||||
* Tim 160
|
||||
* Joe 190
|
||||
* Ann 168
|
||||
* Bob 175
|
||||
* Nick 186
|
||||
* Amy 160
|
||||
* John 159
|
||||
* 输出样例:
|
||||
* Bob Tom Joe Nick
|
||||
* Ann Mike Eva
|
||||
* Tim Amy John
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -76,20 +35,20 @@ int main()
|
||||
int N, K;
|
||||
student students[10000] = {0};
|
||||
Student sp[10000] = {0}, *p = sp;
|
||||
|
||||
|
||||
scanf("%d %d", &N, &K);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
sp[i] = students + i;
|
||||
scanf("%s %d", sp[i]->name, &sp[i]->height);
|
||||
}
|
||||
|
||||
|
||||
qsort(sp, N, sizeof(Student), cmp);
|
||||
|
||||
|
||||
/* print */
|
||||
p = printrow(p, N - N / K * (K - 1)); /* the last row */
|
||||
while(p < sp + N)
|
||||
p = printrow(p, N / K);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/**
|
||||
* 给定N个非0的个位数字,用其中任意2个数字都可以组合成1个2位的数字。要求所有可能组合
|
||||
* 出来的2位数字的和。例如给定2、5、8,则可以组合出:25、28、52、58、82、85,它们的
|
||||
* 和为330。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中先给出N(1<N<10),随后是N个不同的非0个位数字。数字间以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出所有可能组合出来的2位数字的和。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3 2 8 5
|
||||
* 输出样例:
|
||||
* 330
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
+5
-27
@@ -1,25 +1,3 @@
|
||||
/**
|
||||
* 1057. 数零壹(20)
|
||||
*
|
||||
* 给定一串长度不超过105的字符串,本题要求你将其中所有英文字母的序号(字母a-z对应序
|
||||
* 号1-26,不分大小写)相加,得到整数N,然后再分析一下N的二进制表示中有多少0、多少1。
|
||||
* 例如给定字符串“PAT (Basic)”,其字母序号之和为:16+1+20+2+1+19+9+3=71,而71的二
|
||||
* 进制是1000111,即有3个0、4个1。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中给出长度不超过105、以回车结束的字符串。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中先后输出0的个数和1的个数,其间以空格分隔。
|
||||
*
|
||||
* 输入样例:
|
||||
* PAT (Basic)
|
||||
* 输出样例:
|
||||
* 3 4
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -27,15 +5,15 @@ int main()
|
||||
{
|
||||
char c;
|
||||
int sum = 0, count[2] = {0};
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
if(isalpha(c))
|
||||
sum += tolower(c) - 'a' + 1;
|
||||
|
||||
|
||||
for(; sum; sum >>= 1)
|
||||
count[sum & 1]++;
|
||||
|
||||
|
||||
printf("%d %d", count[0], count[1]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+5
-43
@@ -1,41 +1,3 @@
|
||||
/**
|
||||
* 1058. 选择题(20)
|
||||
*
|
||||
* 批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错
|
||||
* 的人最多。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出两个正整数N(<=1000)和M(<=100),分别是学生人数和多选题的个数。
|
||||
* 随后M行,每行顺次给出一道题的满分值(不超过5的正整数)、选项个数(不少于2且不超过
|
||||
* 5的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项
|
||||
* 从小写英文字母a开始顺次排列。各项间以1个空格分隔。最后N行,每行给出一个学生的答题
|
||||
* 情况,其每题答案格式为“(选中的选项个数 选项1 ……)”,按题目顺序给出。注意:题目保证
|
||||
* 学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能
|
||||
* 得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从
|
||||
* 1开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余
|
||||
* 空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3 4
|
||||
* 3 4 2 a c
|
||||
* 2 5 1 b
|
||||
* 5 3 2 b c
|
||||
* 1 5 4 a b d e
|
||||
* (2 a c) (2 b d) (2 a c) (3 a b e)
|
||||
* (2 a c) (1 b) (2 a b) (4 a b d e)
|
||||
* (2 b d) (1 e) (2 b c) (4 a b c d)
|
||||
* 输出样例:
|
||||
* 3
|
||||
* 6
|
||||
* 5
|
||||
* 2 2 3 4
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct prob{
|
||||
@@ -62,7 +24,7 @@ int main()
|
||||
{
|
||||
int N, M, max = 0, useless;
|
||||
Prob probs[100];
|
||||
|
||||
|
||||
/* read the answers for each problem */
|
||||
scanf("%d %d", &N, &M);
|
||||
for(int i = 0; i < M; i++)
|
||||
@@ -71,7 +33,7 @@ int main()
|
||||
probs[i].wrong = 0;
|
||||
probs[i].answer = readanswer();
|
||||
}
|
||||
|
||||
|
||||
/* read every student's answer */
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -88,16 +50,16 @@ int main()
|
||||
}
|
||||
printf("%d\n", score);
|
||||
}
|
||||
|
||||
|
||||
if(max == 0)
|
||||
printf("Too simple");
|
||||
else
|
||||
{
|
||||
printf("%d", max);
|
||||
for(int i = 0; i < M; i++)
|
||||
for(int i = 0; i < M; i++)
|
||||
if(probs[i].wrong == max)
|
||||
printf(" %d", i + 1);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-50
@@ -1,51 +1,3 @@
|
||||
/**
|
||||
* 1059. C语言竞赛(20)
|
||||
*
|
||||
* C语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛。既然竞赛主旨是为了好玩,颁奖规
|
||||
* 则也就制定得很滑稽:
|
||||
*
|
||||
* 0. 冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……)。
|
||||
* 1. 排名为素数的学生将赢得最好的奖品 —— 小黄人玩偶!
|
||||
* 2. 其他人将得到巧克力。
|
||||
*
|
||||
* 给定比赛的最终排名以及一系列参赛者的ID,你要给出这些参赛者应该获得的奖品。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数N(<=10000),是参赛者人数。随后N行给出最终排名,每行按
|
||||
* 排名顺序给出一位参赛者的ID(4位数字组成)。接下来给出一个正整数K以及K个需要查询的ID。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每个要查询的ID,在一行中输出“ID: 奖品”,其中奖品或者是“Mystery Award”(神秘大
|
||||
* 奖)、或者是“Minion”(小黄人)、或者是“Chocolate”(巧克力)。如果所查ID根本不在
|
||||
* 排名里,打印“Are you kidding?”(耍我呢?)。如果该ID已经查过了(即奖品已经领过
|
||||
* 了),打印“ID: Checked”(不能多吃多占)。
|
||||
*
|
||||
* 输入样例:
|
||||
* 6
|
||||
* 1111
|
||||
* 6666
|
||||
* 8888
|
||||
* 1234
|
||||
* 5555
|
||||
* 0001
|
||||
* 6
|
||||
* 8888
|
||||
* 0001
|
||||
* 1111
|
||||
* 2222
|
||||
* 8888
|
||||
* 2222
|
||||
* 输出样例:
|
||||
* 8888: Minion
|
||||
* 0001: Chocolate
|
||||
* 1111: Mystery Award
|
||||
* 2222: Are you kidding?
|
||||
* 8888: Checked
|
||||
* 2222: Are you kidding?
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int isPrime(int n)
|
||||
@@ -60,7 +12,7 @@ int isPrime(int n)
|
||||
int main()
|
||||
{
|
||||
int award[10000] = {0}, N, K, ID;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -82,6 +34,6 @@ int main()
|
||||
case 4: printf("%04d: Checked\n", ID); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+8
-32
@@ -1,47 +1,23 @@
|
||||
/**
|
||||
* 1060. 爱丁顿数(25)
|
||||
*
|
||||
* 英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数”
|
||||
* E,即满足有E天骑车超过E英里的最大整数E。据说爱丁顿自己的E等于87。
|
||||
*
|
||||
* 现给定某人N天的骑车距离,请你算出对应的爱丁顿数E(<=N)。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数N(<=105),即连续骑车的天数;第二行给出N个非负整数,代表
|
||||
* 每天的骑车距离。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中给出N天的爱丁顿数。
|
||||
*
|
||||
* 输入样例:
|
||||
* 10
|
||||
* 6 7 6 9 3 10 8 2 7 8
|
||||
* 输出样例:
|
||||
* 6
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int cmp(const void *a, const void *b)
|
||||
{
|
||||
return *(int*)b - *(int*)a;
|
||||
int cmp(const void *a, const void *b)
|
||||
{
|
||||
return *(int*)b - *(int*)a;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, E, miles[100000];
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
for(int i = 0; i < N; i++)
|
||||
scanf("%d", miles + i);
|
||||
|
||||
|
||||
qsort(miles, N, sizeof(int), cmp);
|
||||
|
||||
|
||||
for(E = 0; E < N && miles[E] > E + 1; E++) ;
|
||||
printf("%d", E);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-35
@@ -1,31 +1,3 @@
|
||||
/**
|
||||
* 1061. 判断题(15)
|
||||
*
|
||||
* 判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出两个不超过100的正整数N和M,分别是学生人数和判断题数量。第二行给
|
||||
* 出M个不超过5的正整数,是每道题的满分值。第三行给出每道题对应的正确答案,0代表“非”,
|
||||
* 1代表“是”。随后N行,每行给出一个学生的解答。数字间均以空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 按照输入的顺序输出每个学生的得分,每个分数占一行。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3 6
|
||||
* 2 1 3 3 4 5
|
||||
* 0 0 1 0 1 1
|
||||
* 0 1 1 0 0 1
|
||||
* 1 0 1 0 1 0
|
||||
* 1 1 0 0 1 1
|
||||
* 输出样例:
|
||||
* 13
|
||||
* 11
|
||||
* 12
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -33,24 +5,24 @@ int main()
|
||||
int N, M;
|
||||
int fullmark[100], answer[100];
|
||||
int score, choice;
|
||||
|
||||
|
||||
scanf("%d %d", &N, &M);
|
||||
for(int i = 0; i < M; i++)
|
||||
for(int i = 0; i < M; i++)
|
||||
scanf("%d", fullmark + i);
|
||||
for(int i = 0; i < M; i++)
|
||||
for(int i = 0; i < M; i++)
|
||||
scanf("%d", answer + i);
|
||||
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
score = 0;
|
||||
for(int j = 0; j < M; j++)
|
||||
for(int j = 0; j < M; j++)
|
||||
{
|
||||
scanf("%d", &choice);
|
||||
if(choice == answer[j])
|
||||
if(choice == answer[j])
|
||||
score += fullmark[j];
|
||||
}
|
||||
printf("%d\n", score);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-29
@@ -1,28 +1,3 @@
|
||||
/**
|
||||
* 1062. 最简分数(20)
|
||||
*
|
||||
* 一个分数一般写成两个整数相除的形式:N/M,其中M不为0。最简分数是指分子和分母没有公
|
||||
* 约数的分数表示形式。
|
||||
*
|
||||
* 现给定两个不相等的正分数 N1/M1 和 N2/M2,要求你按从小到大的顺序列出它们之间分母为
|
||||
* K的最简分数。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中按N/M的格式给出两个正分数,随后是一个正整数分母K,其间以空格分隔。题目
|
||||
* 保证给出的所有整数都不超过1000。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中按N/M的格式列出两个给定分数之间分母为K的所有最简分数,按从小到大的顺序,其
|
||||
* 间以1个空格分隔。行首尾不得有多余空格。题目保证至少有1个输出。
|
||||
*
|
||||
* 输入样例:
|
||||
* 7/18 13/20 12
|
||||
* 输出样例:
|
||||
* 5/12 7/12
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int gcd(int a, int b)
|
||||
@@ -35,16 +10,16 @@ int main()
|
||||
{
|
||||
int N1, N2, M1, M2, K, L, count = 0;
|
||||
scanf("%d/%d %d/%d %d", &N1, &M1, &N2, &M2, &K);
|
||||
|
||||
|
||||
if(N1 * M2 > N2 * M1)
|
||||
{
|
||||
L = N1, N1 = N2, N2 = L;
|
||||
L = M1, M1 = M2, M2 = L;
|
||||
}
|
||||
|
||||
for(L = N1 * K / M1 + 1; N2 * K > M2 * L; L++)
|
||||
|
||||
for(L = N1 * K / M1 + 1; N2 * K > M2 * L; L++)
|
||||
if(gcd(L, K) == 1)
|
||||
printf("%s%d/%d", count++ ? " " : "", L, K);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-31
@@ -1,39 +1,10 @@
|
||||
/**
|
||||
* 1063. 计算谱半径(20)
|
||||
*
|
||||
* 在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界。换言之,对于给定的n个复数
|
||||
* 空间的特征值{a1+b1i, ..., an+bni},它们的模为实部与虚部的平方和的开方,而“谱半
|
||||
* 径”就是最大模。
|
||||
*
|
||||
* 现在给定一些复数空间的特征值,请你计算并输出这些特征值的谱半径。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出正整数N(<= 10000)是输入的特征值的个数。随后N行,每行给出1个特征
|
||||
* 值的实部和虚部,其间以空格分隔。注意:题目保证实部和虚部均为绝对值不超过1000的整数。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出谱半径,四舍五入保留小数点后2位。
|
||||
*
|
||||
* 输入样例:
|
||||
* 5
|
||||
* 0 1
|
||||
* 2 0
|
||||
* -1 0
|
||||
* 3 3
|
||||
* 0 -3
|
||||
* 输出样例:
|
||||
* 4.24
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, R, I, norm = 0;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -42,6 +13,6 @@ int main()
|
||||
norm = R * R + I * I;
|
||||
}
|
||||
printf("%.2lf", sqrt(norm));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-32
@@ -1,49 +1,23 @@
|
||||
/**
|
||||
* 1064. 朋友数(20)
|
||||
*
|
||||
* 如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋
|
||||
* 友证号”。例如123和51就是朋友数,因为1+2+3 = 5+1 = 6,而6就是它们的朋友证号。给定
|
||||
* 一些整数,要求你统计一下它们中有多少个不同的朋友证号。注意:我们默认一个整数自己是
|
||||
* 自己的朋友。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出正整数N。随后一行给出N个正整数,数字间以空格分隔。题目保证所有数字
|
||||
* 小于104。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 首先第一行输出给定数字中不同的朋友证号的个数;随后一行按递增顺序输出这些朋友证号,
|
||||
* 数字间隔一个空格,且行末不得有多余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 8
|
||||
* 123 899 51 998 27 33 36 12
|
||||
* 输出样例:
|
||||
* 4
|
||||
* 3 6 9 26
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, m, sum, friendID[37] = {0}, count = 0;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%d", &m);
|
||||
for(sum = 0; m; m /= 10)
|
||||
for(sum = 0; m; m /= 10)
|
||||
sum += m % 10;
|
||||
if(!friendID[sum])
|
||||
if(!friendID[sum])
|
||||
friendID[sum] = 1, count++;
|
||||
}
|
||||
|
||||
|
||||
printf("%d\n", count);
|
||||
for(int i = 1; i < 37; i++)
|
||||
for(int i = 1; i < 37; i++)
|
||||
if(friendID[i])
|
||||
printf("%d%c", i, --count ? ' ' : '\0');
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+8
-38
@@ -1,33 +1,3 @@
|
||||
/**
|
||||
* 1065. 单身狗(25)
|
||||
*
|
||||
* “单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,
|
||||
* 以便给予特殊关爱。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数N(<=50000),是已知夫妻/伴侣的对数;随后N行,每行给出一
|
||||
* 对夫妻/伴侣——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空
|
||||
* 格分隔;之后给出一个正整数M(<=10000),为参加派对的总人数;随后一行给出这M位客人
|
||||
* 的ID,以空格分隔。题目保证无人重婚或脚踩两条船。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 首先第一行输出落单客人的总人数;随后第二行按ID递增顺序列出落单的客人。ID间用1个
|
||||
* 空格分隔,行的首尾不得有多余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3
|
||||
* 11111 22222
|
||||
* 33333 44444
|
||||
* 55555 66666
|
||||
* 7
|
||||
* 55555 44444 10000 88888 22222 11111 23333
|
||||
* 输出样例:
|
||||
* 5
|
||||
* 10000 23333 44444 55555 88888
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BLANK -1
|
||||
@@ -37,9 +7,9 @@
|
||||
int main()
|
||||
{
|
||||
int couple[100000], count = 0, N, M, ID1, ID2;
|
||||
for(int i = 0; i < 100000; i++)
|
||||
for(int i = 0; i < 100000; i++)
|
||||
couple[i] = BLANK;
|
||||
|
||||
|
||||
/* Read 'couple-list', every pair of 'index' and 'value' are a couple. */
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
@@ -48,7 +18,7 @@ int main()
|
||||
couple[ID1] = ID2;
|
||||
couple[ID2] = ID1;
|
||||
}
|
||||
|
||||
|
||||
scanf("%d", &M);
|
||||
for(int i = 0; i < M; i++) /* Read guest list. */
|
||||
{
|
||||
@@ -58,19 +28,19 @@ int main()
|
||||
else /* Else: not in the 'couple-list' */
|
||||
couple[ID1] = SINGLE, count++; /* set SINGLE */
|
||||
}
|
||||
|
||||
|
||||
/* If couple[ID] is >= 0 (but not signed) but couple[couple[ID]] == SIGNED
|
||||
* (signed in), this means 'ID' didn't come but his/her mate did.
|
||||
* So his/her mate is alone in the party, set to SINGLE. */
|
||||
for(int i = 0; i < 100000; i++)
|
||||
if(couple[i] >= 0 && couple[couple[i]] == SIGNED)
|
||||
for(int i = 0; i < 100000; i++)
|
||||
if(couple[i] >= 0 && couple[couple[i]] == SIGNED)
|
||||
couple[couple[i]] = SINGLE, count++;
|
||||
|
||||
/* Those whose value is SINGLE is either a bachelor or came alone */
|
||||
printf("%d\n", count);
|
||||
for(int i = 0; i < 100000; i++)
|
||||
for(int i = 0; i < 100000; i++)
|
||||
if(couple[i] == SINGLE)
|
||||
printf("%05d%c", i, --count ? ' ' : '\0');
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-31
@@ -1,39 +1,11 @@
|
||||
/**
|
||||
* 1066. 图像过滤(15)
|
||||
*
|
||||
* 图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来。现给定一幅黑白
|
||||
* 图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出一幅图像的分辨率,即两个正整数M和N(0 < M, N <= 500),另外是待
|
||||
* 过滤的灰度值区间端点A和B(0 <= A < B <= 255)、以及指定的替换灰度值。随后M行,每
|
||||
* 行给出N个像素点的灰度值,其间以空格分隔。所有灰度值都在[0, 255]区间内。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 输出按要求过滤后的图像。即输出M行,每行N个像素灰度值,每个灰度值占3位(例如黑色要
|
||||
* 显示为000),其间以一个空格分隔。行首尾不得有多余空格。
|
||||
*
|
||||
* 输入样例:
|
||||
* 3 5 100 150 0
|
||||
* 3 189 254 101 119
|
||||
* 150 233 151 99 100
|
||||
* 88 123 149 0 255
|
||||
* 输出样例:
|
||||
* 003 189 254 000 000
|
||||
* 000 233 151 099 000
|
||||
* 088 000 000 000 255
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, M, A, B, C, D;
|
||||
|
||||
|
||||
scanf("%d %d %d %d %d", &M, &N, &A, &B, &C);
|
||||
|
||||
|
||||
for(int i = 0; i < M; i++)
|
||||
for(int j = 0; j < N; j++)
|
||||
{
|
||||
@@ -41,6 +13,6 @@ int main()
|
||||
if(A <= D && D <= B) D = C;
|
||||
printf("%03d%c", D, j == N - 1 ? '\n' : ' ');
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-46
@@ -1,47 +1,3 @@
|
||||
/**
|
||||
* 1067. 试密码(20)
|
||||
*
|
||||
* 当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数
|
||||
* 时,账号就会被锁死。本题就请你实现这个小功能。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出一个密码(长度不超过20的、不包含空格、Tab、回车的非空字符串)和一
|
||||
* 个正整数N(<= 10),分别是正确的密码和系统允许尝试的次数。随后每行给出一个以回车结
|
||||
* 束的非空字符串,是用户尝试输入的密码。输入保证至少有一次尝试。当读到一行只有单个#
|
||||
* 字符时,输入结束,并且这一行不是用户的输入。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对用户的每个输入,如果是正确的密码且尝试次数不超过N,则在一行中输出“Welcome in”,
|
||||
* 并结束程序;如果是错误的,则在一行中按格式输出“Wrong password: 用户输入的错误密码
|
||||
* ”;当错误尝试达到N次时,再输出一行“Account locked”,并结束程序。
|
||||
*
|
||||
* 输入样例1:
|
||||
* Correct%pw 3
|
||||
* correct%pw
|
||||
* Correct@PW
|
||||
* whatisthepassword!
|
||||
* Correct%pw
|
||||
* #
|
||||
* 输出样例1:
|
||||
* Wrong password: correct%pw
|
||||
* Wrong password: Correct@PW
|
||||
* Wrong password: whatisthepassword!
|
||||
* Account locked
|
||||
* 输入样例2:
|
||||
* cool@gplt 3
|
||||
* coolman@gplt
|
||||
* coollady@gplt
|
||||
* cool@gplt
|
||||
* try again
|
||||
* #
|
||||
* 输出样例2:
|
||||
* Wrong password: coolman@gplt
|
||||
* Wrong password: coollady@gplt
|
||||
* Welcome in
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -50,7 +6,7 @@ int main()
|
||||
{
|
||||
int N;
|
||||
char c, correct[21], user[21];
|
||||
|
||||
|
||||
scanf("%s %d", correct, &N);
|
||||
while(getchar() != '\n');
|
||||
while(N--)
|
||||
@@ -73,6 +29,6 @@ int main()
|
||||
if(!N) puts("Account locked");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-60
@@ -1,60 +1,3 @@
|
||||
/**
|
||||
* 1068. 万绿丛中一点红(20)
|
||||
*
|
||||
* 对于计算机而言,颜色不过是像素点对应的一个24位的数值。现给定一幅分辨率为MxN的画,
|
||||
* 要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围
|
||||
* 8个相邻像素的颜色差充分大。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出三个正整数,分别是M和N(<= 1000),即图像的分辨率;以及TOL,是所
|
||||
* 求像素点与相邻点的颜色差阈值,色差超过TOL的点才被考虑。随后N行,每行给出M个像素
|
||||
* 的颜色值,范围在[0, 2^24)内。所有同行数字间用空格或TAB分开。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中按照“(x, y): color”的格式输出所求像素点的位置以及颜色值,其中位置x和y分
|
||||
* 别是该像素在图像矩阵中的列、行编号(从1开始编号)。如果这样的点不唯一,则输出
|
||||
* “Not Unique”;如果这样的点不存在,则输出“Not Exist”。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 8 6 200
|
||||
* 0 0 0 0 0 0 0 0
|
||||
* 65280 65280 65280 16711479 65280 65280 65280 65280
|
||||
* 16711479 65280 65280 65280 16711680 65280 65280 65280
|
||||
* 65280 65280 65280 65280 65280 65280 165280 165280
|
||||
* 65280 65280 16777015 65280 65280 165280 65480 165280
|
||||
* 16777215 16777215 16777215 16777215 16777215 16777215 16777215 16777215
|
||||
* 输出样例1:
|
||||
* (5, 3): 16711680
|
||||
* 输入样例2:
|
||||
* 4 5 2
|
||||
* 0 0 0 0
|
||||
* 0 0 3 0
|
||||
* 0 0 0 0
|
||||
* 0 5 0 0
|
||||
* 0 0 0 0
|
||||
* 输出样例2:
|
||||
* Not Unique
|
||||
* 输入样例3:
|
||||
* 3 3 5
|
||||
* 1 2 3
|
||||
* 3 4 5
|
||||
* 5 6 7
|
||||
* 输出样例3:
|
||||
* Not Exist
|
||||
**/
|
||||
|
||||
/**
|
||||
* Color difference, see: https://en.wikipedia.org/wiki/Color_difference
|
||||
* Definition: Diff_12 = sqrt((r1 - r2)^2 + (g1 - g2)^2 + (b1 - b2)^2)
|
||||
*
|
||||
* Tips:
|
||||
* 1. The pixel should have the color differences higher than TOL with ALL
|
||||
* pixels around it. Including the pixels on the edge.
|
||||
* 2. And this color should only appears only ONCE in the figure.
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define SQR(X) ((X)*(X))
|
||||
@@ -76,12 +19,12 @@ int main()
|
||||
{
|
||||
int M, N, TOL;
|
||||
scanf("%d %d %d", &M, &N, &TOL);
|
||||
|
||||
|
||||
int fig[1000][1000];
|
||||
for(int i = 0; i < N; i++)
|
||||
for(int j = 0; j < M; j++)
|
||||
scanf("%d", &fig[i][j]);
|
||||
|
||||
|
||||
int count = 0, M0, N0;
|
||||
for(int i = 0; i < N; i ++)
|
||||
for (int j = 0; j < M; j++)
|
||||
@@ -99,7 +42,7 @@ int main()
|
||||
N0 = i;
|
||||
M0 = j;
|
||||
}
|
||||
|
||||
|
||||
if(count == 0) printf("Not Exist");
|
||||
if(count == 1) printf("(%d, %d): %d", M0 + 1, N0 + 1, fig[N0][M0]);
|
||||
if(count >= 2) printf("Not Unique");
|
||||
|
||||
+11
-53
@@ -1,45 +1,3 @@
|
||||
/**
|
||||
* 1069. 微博转发抽奖(20)
|
||||
*
|
||||
* 小明PAT考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔N个人
|
||||
* 就发出一个红包。请你编写程序帮助他确定中奖名单。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出三个正整数M(<= 1000)、N和S,分别是转发的总量、小明决定的中奖间隔、
|
||||
* 以及第一位中奖者的序号(编号从1开始)。随后M行,顺序给出转发微博的网友的昵称(不
|
||||
* 超过20个字符、不包含空格回车的非空字符串)。
|
||||
*
|
||||
* 注意:可能有人转发多次,但不能中奖多次。所以如果处于当前中奖位置的网友已经中过奖,
|
||||
* 则跳过他顺次取下一位。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 按照输入的顺序输出中奖名单,每个昵称占一行。如果没有人中奖,则输出“Keep going...”。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 9 3 2
|
||||
* Imgonnawin!
|
||||
* PickMe
|
||||
* PickMeMeMeee
|
||||
* LookHere
|
||||
* Imgonnawin!
|
||||
* TryAgainAgain
|
||||
* TryAgainAgain
|
||||
* Imgonnawin!
|
||||
* TryAgainAgain
|
||||
* 输出样例1:
|
||||
* PickMe
|
||||
* Imgonnawin!
|
||||
* TryAgainAgain
|
||||
* 输入样例2:
|
||||
* 2 3 5
|
||||
* Imgonnawin!
|
||||
* PickMe
|
||||
* 输出样例2:
|
||||
* Keep going...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -47,31 +5,31 @@ int main()
|
||||
{
|
||||
char s[1000][21] = {{0}}, line[21];
|
||||
int M, N, S, m, count = 0, r = 0;
|
||||
|
||||
|
||||
scanf("%d %d %d", &M, &N, &S);
|
||||
|
||||
|
||||
for(m = 0, S--; m < M; m++)
|
||||
{
|
||||
scanf("%s", line);
|
||||
if(m == S + count * N + r)
|
||||
{
|
||||
int flag = 1;
|
||||
for(int i = 0; i < count && flag; i++)
|
||||
if(!strcmp(s[i], line))
|
||||
for(int i = 0; i < count && flag; i++)
|
||||
if(!strcmp(s[i], line))
|
||||
{
|
||||
flag = 0;
|
||||
r++;
|
||||
flag = 0;
|
||||
r++;
|
||||
break;
|
||||
}
|
||||
if(flag)
|
||||
if(flag)
|
||||
strcpy(s[count++], line);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < count; i++)
|
||||
|
||||
for(int i = 0; i < count; i++)
|
||||
printf("%s\n", s[i]);
|
||||
if(!count)
|
||||
if(!count)
|
||||
printf("Keep going...");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-32
@@ -1,54 +1,29 @@
|
||||
/**
|
||||
* 1070. 结绳(25)
|
||||
*
|
||||
* 给定一段一段的绳子,你需要把它们串成一条绳。每次串连的时候,是把两段绳子对折,再
|
||||
* 如下图所示套接在一起。这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段
|
||||
* 绳子串连。每次串连后,原来两段绳子的长度就会减半。
|
||||
*
|
||||
* 给定N段绳子的长度,你需要找出它们能串成的绳子的最大长度。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例第1行给出正整数N (2 <= N <= 104);第2行给
|
||||
* 出N个正整数,即原始绳段的长度,数字间以空格分隔。所有整数都不超过104。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出能够串成的绳子的最大长度。结果向下取整,即取为不超过最大长度的最近整数。
|
||||
*
|
||||
* 输入样例:
|
||||
* 8
|
||||
* 10 15 12 3 4 13 1 15
|
||||
* 输出样例:
|
||||
* 14
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int l[10001] = {0}, N, i;
|
||||
double length = 0;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int j = 0; j < N; j++)
|
||||
{
|
||||
scanf("%d", &i);
|
||||
scanf("%d", &i);
|
||||
l[i]++; /* record counts */
|
||||
}
|
||||
|
||||
|
||||
for(i = 0; i < 10001; i++) /* find the shortest, special case */
|
||||
if(l[i])
|
||||
if(l[i])
|
||||
{
|
||||
length = i;
|
||||
break;
|
||||
}
|
||||
|
||||
for(; i < 10001; i++) /* make new ropes */
|
||||
while(l[i]--)
|
||||
while(l[i]--)
|
||||
length = (length + i) / 2;
|
||||
|
||||
|
||||
printf("%d", (int)length);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,54 +1,3 @@
|
||||
/**
|
||||
* 1071. 小赌怡情(15)
|
||||
*
|
||||
* 常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌
|
||||
* 第二个整数将会比第一个数大还是小;玩家下注t个筹码后,计算机给出第二个数。若玩家猜对
|
||||
* 了,则系统奖励玩家t个筹码;否则扣除玩家t个筹码。
|
||||
*
|
||||
* 注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数。当玩家输光了全部筹码后,游戏就
|
||||
* 结束。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出2个正整数T和K(<=100),分别是系统在初始状态下赠送给玩家的筹码数、
|
||||
* 以及需要处理的游戏次数。随后K行,每行对应一次游戏,顺序给出4个数字:
|
||||
*
|
||||
* n1 b t n2
|
||||
*
|
||||
* 其中n1和n2是计算机先后给出的两个[0, 9]内的整数,保证两个数字不相等。b为0表示玩家赌
|
||||
* “小”,为1表示玩家赌“大”。t表示玩家下注的筹码数,保证在整型范围内。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每一次游戏,根据下列情况对应输出(其中t是玩家下注量,x是玩家当前持有的筹码量):
|
||||
*
|
||||
* 玩家赢,输出“Win t! Total = x.”;
|
||||
* 玩家输,输出“Lose t. Total = x.”;
|
||||
* 玩家下注超过持有的筹码量,输出“Not enough tokens. Total = x.”;
|
||||
* 玩家输光后,输出“Game Over.”并结束程序。
|
||||
* 输入样例1:
|
||||
* 100 4
|
||||
* 8 0 100 2
|
||||
* 3 1 50 1
|
||||
* 5 1 200 6
|
||||
* 7 0 200 8
|
||||
* 输出样例1:
|
||||
* Win 100! Total = 200.
|
||||
* Lose 50. Total = 150.
|
||||
* Not enough tokens. Total = 150.
|
||||
* Not enough tokens. Total = 150.
|
||||
* 输入样例2:
|
||||
* 100 4
|
||||
* 8 0 100 2
|
||||
* 3 1 200 1
|
||||
* 5 1 200 6
|
||||
* 7 0 200 8
|
||||
* 输出样例2:
|
||||
* Win 100! Total = 200.
|
||||
* Lose 200. Total = 0.
|
||||
* Game Over.
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
|
||||
+2
-41
@@ -1,53 +1,14 @@
|
||||
/**
|
||||
* 1072. 开学寄语(20)
|
||||
*
|
||||
* 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其QQ,封其电脑,
|
||||
* 夺其手机,收其ipad,断其wifi,使其百无聊赖,然后,净面、理发、整衣,然后思过、读
|
||||
* 书、锻炼、明智、开悟、精进。而后必成大器也!
|
||||
*
|
||||
* 本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出两个正整数N(<= 1000)和M(<= 6),分别是学生人数和需要被查缴的物品
|
||||
* 种类数。第二行给出M个需要被查缴的物品编号,其中编号为4位数字。随后N行,每行给出一位
|
||||
* 学生的姓名缩写(由1-4个大写英文字母组成)、个人物品数量K(0 <= K <= 10)、以及
|
||||
* K个物品的编号。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 顺次检查每个学生携带的物品,如果有需要被查缴的物品存在,则按以下格式输出该生的信息
|
||||
* 和其需要被查缴的物品的信息(注意行末不得有多余空格):
|
||||
*
|
||||
* 姓名缩写: 物品编号1 物品编号2 ……
|
||||
* 最后一行输出存在问题的学生的总人数和被查缴物品的总数。
|
||||
*
|
||||
* 输入样例:
|
||||
* 4 2
|
||||
* 2333 6666
|
||||
* CYLL 3 1234 2345 3456
|
||||
* U 4 9966 6666 8888 6666
|
||||
* GG 2 2333 7777
|
||||
* JJ 3 0012 6666 2333
|
||||
*
|
||||
* 输出样例:
|
||||
* U: 6666 6666
|
||||
* GG: 2333
|
||||
* JJ: 6666 2333
|
||||
* 3 5
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, M, K, SNlist[10], SNtarget;
|
||||
char name[5];
|
||||
|
||||
|
||||
scanf("%d %d", &N, &M);
|
||||
for(int i = 0; i < M; i ++)
|
||||
scanf("%d", SNlist + i);
|
||||
|
||||
|
||||
int flag, student_total = 0, item_total = 0;
|
||||
for(int i = 0; i < N; i ++)
|
||||
{
|
||||
|
||||
+9
-65
@@ -1,59 +1,3 @@
|
||||
/**
|
||||
* 1073. 多选题常见计分法(20)
|
||||
*
|
||||
* 批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生
|
||||
* 选择了部分正确选项,并且没有选择任何错误选项,则得到50%分数;如果考生选择了任何一个
|
||||
* 错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选
|
||||
* 项错的人最多。
|
||||
*
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出两个正整数N(<=1000)和M(<=100),分别是学生人数和多选题的个数。
|
||||
* 随后M行,每行顺次给出一道题的满分值(不超过5的正整数)、选项个数(不少于2且不超过5
|
||||
* 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从
|
||||
* 小写英文字母a开始顺次排列。各项间以1个空格分隔。最后N行,每行给出一个学生的答题情
|
||||
* 况,其每题答案格式为“(选中的选项个数 选项1 ……)”,按题目顺序给出。注意:题目保证学
|
||||
* 生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 按照输入的顺序给出每个学生的得分,每个分数占一行,输出小数点后1位。最后输出错得最多
|
||||
* 的题目选项的信息,格式为:“错误次数 题目编号(题目按照输入的顺序从1开始编号)-
|
||||
* 选项号”。如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺
|
||||
* 序输出。行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。
|
||||
*
|
||||
* 输入样例1:
|
||||
* 3 4
|
||||
* 3 4 2 a c
|
||||
* 2 5 1 b
|
||||
* 5 3 2 b c
|
||||
* 1 5 4 a b d e
|
||||
* (2 a c) (3 b d e) (2 a c) (3 a b e)
|
||||
* (2 a c) (1 b) (2 a b) (4 a b d e)
|
||||
* (2 b d) (1 e) (1 c) (4 a b c d)
|
||||
*
|
||||
* 输出样例1:
|
||||
* 3.5
|
||||
* 6.0
|
||||
* 2.5
|
||||
* 2 2-e
|
||||
* 2 3-a
|
||||
* 2 3-b
|
||||
*
|
||||
* 输入样例2:
|
||||
* 2 2
|
||||
* 3 4 2 a c
|
||||
* 2 5 1 b
|
||||
* (2 a c) (1 b)
|
||||
* (2 a c) (1 b)
|
||||
*
|
||||
* 输出样例2:
|
||||
* 5.0
|
||||
* 5.0
|
||||
* Too simple
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_M 100
|
||||
@@ -63,7 +7,7 @@ int readanswer()
|
||||
{
|
||||
char c;
|
||||
int answer = 0, count;
|
||||
|
||||
|
||||
scanf("%d", &count);
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
@@ -75,10 +19,10 @@ int readanswer()
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, M, full_score[MAX_M] = {0}, correct_ans[MAX_M] = {0},
|
||||
int N, M, full_score[MAX_M] = {0}, correct_ans[MAX_M] = {0},
|
||||
wrong_ans[MAX_M] = {0}, wrong_count[MAX_M][5] = {{0}},
|
||||
wrong_count_max = 0;
|
||||
|
||||
|
||||
scanf("%d %d", &N, &M);
|
||||
/* Read M lines */
|
||||
int count_options;
|
||||
@@ -87,7 +31,7 @@ int main()
|
||||
scanf("%d %d", full_score + i, &count_options);
|
||||
correct_ans[i] = readanswer();
|
||||
}
|
||||
|
||||
|
||||
/* Read N lines */
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
@@ -98,12 +42,12 @@ int main()
|
||||
while(getchar() != '(');
|
||||
answer = readanswer();
|
||||
wrong_ans[j] = answer ^ correct_ans[j];
|
||||
|
||||
|
||||
if(wrong_ans[j] == 0) /* all correct */
|
||||
score += full_score[j];
|
||||
else if((wrong_ans[j] | correct_ans[j]) == correct_ans[j])
|
||||
else if((wrong_ans[j] | correct_ans[j]) == correct_ans[j])
|
||||
score += 0.5 * full_score[j]; /* partially corrent */
|
||||
|
||||
|
||||
/* For every option, record the number of students got wrong */
|
||||
for(int k = 0; k < MAX_OPTIONS; k++)
|
||||
{
|
||||
@@ -111,12 +55,12 @@ int main()
|
||||
if(wrong_count[j][k] > wrong_count_max)
|
||||
wrong_count_max = wrong_count[j][k];
|
||||
}
|
||||
|
||||
|
||||
while(getchar() != ')');
|
||||
}
|
||||
printf("%.1f\n", score);
|
||||
}
|
||||
|
||||
|
||||
if(wrong_count_max == 0)
|
||||
printf("Too simple");
|
||||
else
|
||||
|
||||
+8
-42
@@ -1,37 +1,3 @@
|
||||
/**
|
||||
* 1074. 宇宙无敌加法器(20)
|
||||
*
|
||||
* 地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在PAT星人开挂的世界
|
||||
* 里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个PAT星人都必须熟
|
||||
* 记各位数字的进制表,例如“……0527”就表示最低位是7进制数、第2位是2进制数、第3位是5进
|
||||
* 制数、第4位是10进制数,等等。每一位的进制d或者是0(表示十进制)、或者是[2,9]区间
|
||||
* 内的整数。理论上这个进制表应该包含无穷多位数字,但从实际应用出发,PAT星人通常只需要
|
||||
* 记住前20位就够用了,以后各位默认为10进制。
|
||||
*
|
||||
* 在这样的数字系统中,即使是简单的加法运算也变得不简单。例如对应进制表“0527”,该如何
|
||||
* 计算“6203+415”呢?我们得首先计算最低位:3+5=8;因为最低位是7进制的,所以我们得
|
||||
* 到1和1个进位。第2位是:0+1+1(进位)=2;因为此位是2进制的,所以我们得到0和1个进
|
||||
* 位。第3位是:2+4+1(进位)=7;因为此位是5进制的,所以我们得到2和1个进位。第4位
|
||||
* 是:6+1(进位)=7;因为此位是10进制的,所以我们就得到7。最后我们得到:6203+415=
|
||||
* 7201。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入首先在第一行给出一个N位的进制表(0 < N <=20),以回车结束。 随后两行,每行给
|
||||
* 出一个不超过N位的正的PAT数。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出两个PAT数之和。
|
||||
*
|
||||
* 输入样例:
|
||||
* 30527
|
||||
* 06203
|
||||
* 415
|
||||
* 输出样例:
|
||||
* 7201
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -39,39 +5,39 @@ int main()
|
||||
{
|
||||
int nBase, nA, nB, nS = 21, base, a, b;
|
||||
char sBase[21] = {0}, sA[21] = {0}, sB[21] = {0}, sSum[22] = {0};
|
||||
|
||||
|
||||
/* Read base table, number A and B into strings */
|
||||
scanf("%s %s %s", sBase, sA, sB);
|
||||
|
||||
|
||||
nBase = strlen(sBase);
|
||||
nA = strlen(sA);
|
||||
nB = strlen(sB);
|
||||
|
||||
|
||||
for(int i = 0; i < nBase; i++)
|
||||
{
|
||||
/* Transform corresponding digit to integers */
|
||||
a = nA <= i ? 0 : sA[nA - i - 1] - '0';
|
||||
b = nB <= i ? 0 : sB[nB - i - 1] - '0';
|
||||
base = sBase[nBase - i - 1] == '0' ? 10 : sBase[nBase - i - 1] - '0';
|
||||
|
||||
|
||||
/* Calculate ith digit A + B, temperately store integers here */
|
||||
sSum[nS - i - 1] += a + b;
|
||||
sSum[nS - i - 2] += sSum[nS - i - 1] / base; /* carry */
|
||||
sSum[nS - i - 1] = sSum[nS - i - 1] % base;
|
||||
}
|
||||
|
||||
|
||||
/* Change to char type */
|
||||
for(int i = 0; i < 21; i++)
|
||||
sSum[i] += '0';
|
||||
|
||||
|
||||
/* find the first non-zero bit */
|
||||
for(int first = 0; first < 21; first++)
|
||||
for(int first = 0; first < 21; first++)
|
||||
if(sSum[first] != 0 && sSum[first] != '0')
|
||||
{
|
||||
puts(sSum + first);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* If A + B = 0, then all bits are zero */
|
||||
printf("0");
|
||||
return 0;
|
||||
|
||||
+3
-51
@@ -1,58 +1,10 @@
|
||||
/**
|
||||
* 1075. 链表元素分类(25)
|
||||
*
|
||||
* 给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的
|
||||
* 前面,而[0, K]区间内的元素都排在大于K的元素前面。但每一类内部元素的顺序是不能改变
|
||||
* 的。例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K为10,则输出应该为
|
||||
* -4→-6→-2→7→0→5→10→18→11。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 每个输入包含1个测试用例。每个测试用例第1行给出:第1个结点的地址;结点总个数,即正整
|
||||
* 数N (<= 105);以及正整数K (<=1000)。结点的地址是5位非负整数,NULL地址用-1表示。
|
||||
*
|
||||
* 接下来有N行,每行格式为:
|
||||
*
|
||||
* Address Data Next
|
||||
*
|
||||
* 其中Address是结点地址;Data是该结点保存的数据,为[-105, 105]区间内的整数;Next
|
||||
* 是下一结点的地址。题目保证给出的链表不为空。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每个测试用例,按链表从头到尾的顺序输出重排后的结果链表,其上每个结点占一行,格式与
|
||||
* 输入相同。
|
||||
*
|
||||
* 输入样例:
|
||||
* 00100 9 10
|
||||
* 23333 10 27777
|
||||
* 00000 0 99999
|
||||
* 00100 18 12309
|
||||
* 68237 -6 23333
|
||||
* 33218 -4 00000
|
||||
* 48652 -2 -1
|
||||
* 99999 5 68237
|
||||
* 27777 11 48652
|
||||
* 12309 7 33218
|
||||
* 输出样例:
|
||||
* 33218 -4 68237
|
||||
* 68237 -6 48652
|
||||
* 48652 -2 12309
|
||||
* 12309 7 00000
|
||||
* 00000 0 99999
|
||||
* 99999 5 23333
|
||||
* 23333 10 00100
|
||||
* 00100 18 27777
|
||||
* 27777 11 -1
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int data[100000] = {0}, next[100000] = {0},
|
||||
firstaddr, addr, lastaddr = -1, N, K;
|
||||
|
||||
|
||||
/* Read */
|
||||
scanf("%d %d %d", &firstaddr, &N, &K);
|
||||
for(int i = 0; i < N; i++)
|
||||
@@ -60,7 +12,7 @@ int main()
|
||||
scanf("%d", &addr);
|
||||
scanf("%d %d", data + addr, next + addr);
|
||||
}
|
||||
|
||||
|
||||
/* Scan three times */
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
@@ -80,6 +32,6 @@ int main()
|
||||
}
|
||||
}
|
||||
printf(" -1");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-33
@@ -1,43 +1,12 @@
|
||||
/**
|
||||
* 下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用wifi,又怕耽误亲们的
|
||||
* 学习,现将wifi密码设置为下列数学题答案:A-1;B-2;C-3;D-4;请同学们自己作答,每两日
|
||||
* 一换。谢谢合作!!~”—— 老师们为了促进学生学习也是拼了…… 本题就要求你写程序把一系列题目的
|
||||
* 答案按照卷子上给出的对应关系翻译成wifi的密码。这里简单假设每道选择题都有4个选项,有且只有
|
||||
* 1个正确答案。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数N(<= 100),随后N行,每行按照“编号-答案”的格式给出一道题的4个
|
||||
* 选项,“T”表示正确选项,“F”表示错误选项。选项间用空格分隔。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 在一行中输出wifi密码。
|
||||
*
|
||||
* 输入样例:
|
||||
* 8
|
||||
* A-T B-F C-F D-F
|
||||
* C-T B-F A-F D-F
|
||||
* A-F D-F C-F B-T
|
||||
* B-T A-F C-F D-F
|
||||
* B-F D-T A-F C-F
|
||||
* A-T C-F B-F D-F
|
||||
* D-T B-F C-F A-F
|
||||
* C-T A-F B-F D-F
|
||||
*
|
||||
* 输出样例:
|
||||
* 13224143
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char string[4];
|
||||
|
||||
|
||||
while(scanf("%s", string) != EOF)
|
||||
if(string[2] == 'T')
|
||||
putchar("1234"[string[0] - 'A']);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-43
@@ -1,42 +1,3 @@
|
||||
/**
|
||||
* 1077. 互评成绩计算 (20)
|
||||
*
|
||||
* 在浙大的计算机专业课中,经常有互评分组报告这个环节。一个组上台介绍自己的工作,其他
|
||||
* 组在台下为其表现评分。最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一
|
||||
* 个最高分和一个最低分,剩下的分数取平均分记为 G1;老师给这个组的评分记为 G2。该组
|
||||
* 得分为 (G1+G2)/2,最后结果四舍五入后保留整数分。本题就要求你写个程序帮助老师计算
|
||||
* 每个组的互评成绩。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出两个正整数N(> 3)和M,分别是分组数和满分,均不超过100。随后N行,
|
||||
* 每行给出该组得到的N个分数(均保证为整型范围内的整数),其中第1个是老师给出的评分,
|
||||
* 后面 N-1 个是其他组给的评分。合法的输入应该是[0, M]区间内的整数,若不在合法区间
|
||||
* 内,则该分数须被忽略。题目保证老师的评分都是合法的,并且每个组至少会有3个来自同学的
|
||||
* 合法评分。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 为每个组输出其最终得分。每个得分占一行。
|
||||
*
|
||||
* 输入样例:
|
||||
* 6 50
|
||||
* 42 49 49 35 38 41
|
||||
* 36 51 50 28 -1 30
|
||||
* 40 36 41 33 47 49
|
||||
* 30 250 -25 27 45 31
|
||||
* 48 0 0 50 50 1234
|
||||
* 43 41 36 29 42 29
|
||||
*
|
||||
* 输出样例:
|
||||
* 42
|
||||
* 33
|
||||
* 41
|
||||
* 31
|
||||
* 37
|
||||
* 39
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
@@ -44,11 +5,11 @@ int main()
|
||||
int N, M, count;
|
||||
double G1, G2, Gsum, Gmax, Gmin, G;
|
||||
scanf("%d %d", &N, &M);
|
||||
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%lf", &G2);
|
||||
|
||||
|
||||
/* Calculate G1 */
|
||||
Gsum = 0;
|
||||
count = 0;
|
||||
@@ -68,9 +29,9 @@ int main()
|
||||
}
|
||||
}
|
||||
G1 = (Gsum - Gmax - Gmin) / (count - 2); /* Average */
|
||||
|
||||
|
||||
printf("%d\n", (int)((G1 + G2 + 1) / 2));
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-38
@@ -1,44 +1,10 @@
|
||||
/**
|
||||
* 1078. 字符串压缩与解压 (20)
|
||||
*
|
||||
* 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段
|
||||
* 用这个字符和片段中含有这个字符的个数来表示。例如 ccccc 就用 5c 来表示。如果字符
|
||||
* 没有重复,就原样输出。例如 aba 压缩后仍然是 aba。
|
||||
*
|
||||
* 解压方法就是反过来,把形如 5c 这样的表示恢复为 ccccc。
|
||||
*
|
||||
* 本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串
|
||||
* 是完全由英文字母和空格组成的非空字符串。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个字符,如果是 C 就表示下面的字符串需要被压缩;如果是 D 就表示下
|
||||
* 面的字符串需要被解压。第二行给出需要被压缩或解压的不超过1000个字符的字符串,以回
|
||||
* 车结尾。题目保证字符重复个数在整型范围内,且输出文件不超过1MB。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 根据要求压缩或解压字符串,并在一行中输出结果。
|
||||
*
|
||||
* 输入样例 1:
|
||||
* C
|
||||
* TTTTThhiiiis isssss a tesssst CAaaa as
|
||||
* 输出样例 1:
|
||||
* 5T2h4is i5s a3 te4st CA3a as
|
||||
* 输入样例 2:
|
||||
* D
|
||||
* 5T2h4is i5s a3 te4st CA3a as10Z
|
||||
* 输出样例 2:
|
||||
* TTTTThhiiiis isssss a tesssst CAaaa asZZZZZZZZZZ
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void compress()
|
||||
{
|
||||
char previous = getchar(), current;
|
||||
int count = 1;
|
||||
|
||||
|
||||
while((current = getchar()))
|
||||
{
|
||||
if(current == previous)
|
||||
@@ -53,7 +19,7 @@ void compress()
|
||||
previous = current;
|
||||
count = 1;
|
||||
}
|
||||
|
||||
|
||||
if(current == '\n') /* Don't put this in while() */
|
||||
break;
|
||||
}
|
||||
@@ -63,7 +29,7 @@ void decompress()
|
||||
{
|
||||
char c;
|
||||
int count = 0;
|
||||
|
||||
|
||||
while((c = getchar()) != '\n')
|
||||
{
|
||||
if(c >= '0' && c <= '9') /* If it is number */
|
||||
@@ -96,6 +62,6 @@ int main()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-55
@@ -1,55 +1,3 @@
|
||||
/**
|
||||
* 1079. 延迟的回文数 (20)
|
||||
*
|
||||
* 给定一个 k+1 位的正整数 N,写成 ak...a1a0 的形式,其中对所有 i 有
|
||||
* 0 <= ai < 10 且 ak > 0。N 被称为一个回文数,当且仅当对所有 i 有 ai = ak-i。
|
||||
* 零也被定义为一个回文数。
|
||||
*
|
||||
* 非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,
|
||||
* 如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回文数出现。如果一个非
|
||||
* 回文数可以变出回文数,就称这个数为延迟的回文数。
|
||||
* (定义翻译自 https://en.wikipedia.org/wiki/Palindromic_number)
|
||||
*
|
||||
* 给定任意一个正整数,本题要求你找到其变出的那个回文数。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在一行中给出一个不超过1000位的正整数。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对给定的整数,一行一行输出其变出回文数的过程。每行格式如下
|
||||
*
|
||||
* A + B = C
|
||||
* 其中A是原始的数字,B是A的逆转数,C是它们的和。A从输入的整数开始。重复操作直到C
|
||||
* 在10步以内变成回文数,这时在一行中输出“C is a palindromic number.”;或者
|
||||
* 如果10步都没能得到回文数,最后就在一行中输出“Not found in 10 iterations.”。
|
||||
*
|
||||
* 输入样例 1:
|
||||
* 97152
|
||||
*
|
||||
* 输出样例 1:
|
||||
* 97152 + 25179 = 122331
|
||||
* 122331 + 133221 = 255552
|
||||
* 255552 is a palindromic number.
|
||||
*
|
||||
* 输入样例 2:
|
||||
* 196
|
||||
*
|
||||
* 输出样例 2:
|
||||
* 196 + 691 = 887
|
||||
* 887 + 788 = 1675
|
||||
* 1675 + 5761 = 7436
|
||||
* 7436 + 6347 = 13783
|
||||
* 13783 + 38731 = 52514
|
||||
* 52514 + 41525 = 94039
|
||||
* 94039 + 93049 = 187088
|
||||
* 187088 + 880781 = 1067869
|
||||
* 1067869 + 9687601 = 10755470
|
||||
* 10755470 + 07455701 = 18211171
|
||||
* Not found in 10 iterations.
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -90,7 +38,7 @@ int main()
|
||||
{
|
||||
int i;
|
||||
char a[1011] = {0}, b[1011] = {0};
|
||||
|
||||
|
||||
scanf("%s", a);
|
||||
for (i = 0; i < 10 && !isPalindromicNumber(a); i++)
|
||||
{
|
||||
@@ -99,11 +47,11 @@ int main()
|
||||
addBtoA(a, b);
|
||||
printf("%s\n", a);
|
||||
}
|
||||
|
||||
|
||||
if(i == 10)
|
||||
printf("Not found in 10 iterations.");
|
||||
else
|
||||
printf("%s is a palindromic number.", a);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-64
@@ -1,64 +1,3 @@
|
||||
/**
|
||||
* 1080. MOOC期终成绩 (25)
|
||||
*
|
||||
* 对于在中国大学MOOC(http://www.icourse163.org/)学习“数据结构”课程的学生,
|
||||
* 想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于
|
||||
* 60分(满分100)。总评成绩的计算公式为 G = (G期中x 40% + G期末x 60%),如果
|
||||
* G期中 > G期末;否则总评 G 就是 G期末。这里 G期中 和 G期末 分别为学生的期中和
|
||||
* 期末成绩。
|
||||
*
|
||||
* 现在的问题是,每次考试都产生一张独立的成绩单。本题就请你编写程序,把不同的成绩单合
|
||||
* 为一张。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入在第一行给出3个整数,分别是 P(做了在线编程作业的学生数)、M(参加了期中考试的
|
||||
* 学生数)、N(参加了期末考试的学生数)。每个数都不超过10000。
|
||||
*
|
||||
* 接下来有三块输入。第一块包含 P 个在线编程成绩 G编程;第二块包含 M 个期中考试成绩
|
||||
* G期中;第三块包含 N 个期末考试成绩 G期末。每个成绩占一行,格式为:学生学号 分数。
|
||||
* 其中学生学号为不超过20个字符的英文字母和数字;分数是非负整数(编程总分最高为900分,
|
||||
* 期中和期末的最高分为100分)。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 打印出获得合格证书的学生名单。每个学生占一行,格式为:
|
||||
*
|
||||
* 学生学号 G编程 G期中 G期末 G
|
||||
*
|
||||
* 如果有的成绩不存在(例如某人没参加期中考试),则在相应的位置输出“-1”。输出顺序为按
|
||||
* 照总评分数(四舍五入精确到整数)递减。若有并列,则按学号递增。题目保证学号没有重复,
|
||||
* 且至少存在1个合格的学生。
|
||||
*
|
||||
* 输入样例:
|
||||
* 6 6 7
|
||||
* 01234 880
|
||||
* a1903 199
|
||||
* ydjh2 200
|
||||
* wehu8 300
|
||||
* dx86w 220
|
||||
* missing 400
|
||||
* ydhfu77 99
|
||||
* wehu8 55
|
||||
* ydjh2 98
|
||||
* dx86w 88
|
||||
* a1903 86
|
||||
* 01234 39
|
||||
* ydhfu77 88
|
||||
* a1903 66
|
||||
* 01234 58
|
||||
* wehu8 84
|
||||
* ydjh2 82
|
||||
* missing 99
|
||||
* dx86w 81
|
||||
*
|
||||
* 输出样例:
|
||||
* missing 400 -1 99 99
|
||||
* ydjh2 200 98 82 88
|
||||
* dx86w 220 88 81 84
|
||||
* wehu8 300 55 84 84
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -96,11 +35,11 @@ int main()
|
||||
{
|
||||
int P, M, N;
|
||||
scanf("%d %d %d", &P, &M, &N);
|
||||
|
||||
|
||||
int score, count = 0;
|
||||
char name[21];
|
||||
Score buf[10000], *scores[10000] = {0}, *s = buf;
|
||||
|
||||
|
||||
for(int i = 0; i < P; i++) /* Read programming grade */
|
||||
{
|
||||
scanf("%s %d", name, &score);
|
||||
@@ -114,7 +53,7 @@ int main()
|
||||
scores[count++] = s++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Sort by name for future searchings using bsearch */
|
||||
qsort(scores, count, sizeof(Score*), cmp_sort_name);
|
||||
|
||||
|
||||
+2
-53
@@ -1,54 +1,3 @@
|
||||
/**
|
||||
* 1081. 检查密码 (15)
|
||||
* 时间限制
|
||||
* 400 ms
|
||||
* 内存限制
|
||||
* 65536 kB
|
||||
* 代码长度限制
|
||||
* 8000 B
|
||||
* 判题程序
|
||||
* Standard
|
||||
* 作者
|
||||
* CHEN, Yue
|
||||
*
|
||||
* 本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用
|
||||
* 户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点".",还
|
||||
* 必须既有字母也有数字。
|
||||
*
|
||||
* 输入格式:
|
||||
*
|
||||
* 输入第一行给出一个正整数 N(<=100),随后 N 行,每行给出一个用户设置的密码,
|
||||
* 为不超过80个字符的非空字符串,以回车结束。
|
||||
*
|
||||
* 输出格式:
|
||||
*
|
||||
* 对每个用户的密码,在一行中输出系统反馈信息,分以下5种:
|
||||
*
|
||||
* 如果密码合法,输出“Your password is wan mei.”;
|
||||
* 如果密码太短,不论合法与否,都输出“Your password is tai duan le.”;
|
||||
* 如果密码长度合法,但存在不合法字符,则输出“Your password is tai luan le.”;
|
||||
* 如果密码长度合法,但只有字母没有数字,则输出“Your password needs shu zi.”;
|
||||
* 如果密码长度合法,但只有数字没有字母,则输出“Your password needs zi mu.”。
|
||||
*
|
||||
* 输入样例:
|
||||
*
|
||||
* 5
|
||||
* 123s
|
||||
* zheshi.wodepw
|
||||
* 1234.5678
|
||||
* WanMei23333
|
||||
* pass*word.6
|
||||
*
|
||||
* 输出样例:
|
||||
*
|
||||
* Your password is tai duan le.
|
||||
* Your password needs shu zi.
|
||||
* Your password needs zi mu.
|
||||
* Your password is wan mei.
|
||||
* Your password is tai luan le.
|
||||
**/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -56,7 +5,7 @@ int main()
|
||||
{
|
||||
char c;
|
||||
int N, count, num_digit, num_alpha, num_else;
|
||||
|
||||
|
||||
scanf("%d", &N);
|
||||
while(getchar() == '\n');
|
||||
for(int i = 0; i < N; i++)
|
||||
@@ -74,6 +23,6 @@ int main()
|
||||
else if(num_digit && !num_alpha) puts("Your password needs zi mu.");
|
||||
else puts("Your password is wan mei.");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user