mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-03 00:23:15 +08:00
add b109[1-4]
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int M, N, K, L, mask;
|
||||
|
||||
scanf("%d", &M);
|
||||
for(int i = 0; i < M; i++)
|
||||
{
|
||||
scanf("%d", &K);
|
||||
for(N = 1; N < 10; N++)
|
||||
{
|
||||
L = N * K * K;
|
||||
|
||||
/* compare the lowest digits one by one */
|
||||
for(mask = 1; mask <= K; mask *= 10)
|
||||
if(L / mask % 10 != K / mask % 10)
|
||||
break;
|
||||
|
||||
if(mask > K) /* all passed! */
|
||||
{
|
||||
printf("%d %d\n", N, L);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(N == 10) /* No results */
|
||||
printf("No\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, M, cur, max = 0, sales[1000] = {0};
|
||||
|
||||
scanf("%d %d", &N, &M);
|
||||
for(int i = 0; i < M; i++)
|
||||
{
|
||||
for(int j = 0; j < N; j++)
|
||||
{
|
||||
scanf("%d", &cur);
|
||||
sales[j] += cur;
|
||||
}
|
||||
}
|
||||
|
||||
/* find the max */
|
||||
for(int i = 0; i < N; i++)
|
||||
if(max < sales[i])
|
||||
max = sales[i];
|
||||
|
||||
/* print all the indexes of max sales */
|
||||
printf("%d", max);
|
||||
for(int i = 0, count = 0; i < N; i++)
|
||||
if(sales[i] == max)
|
||||
printf("%c%d", count++ ? ' ' : '\n', i + 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c;
|
||||
int lines = 0, ascii[128] = {0};
|
||||
|
||||
while(lines < 2)
|
||||
{
|
||||
c = getchar();
|
||||
if(c == '\n')
|
||||
lines++;
|
||||
else if(!ascii[(int)c])
|
||||
{
|
||||
putchar(c);
|
||||
ascii[(int)c]++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int iPrime(int n)
|
||||
{
|
||||
if(n < 2)
|
||||
return 0;
|
||||
for(int i = 2; i * i <= n; i++)
|
||||
if(n % i == 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char N[1000], n[10] = {0};
|
||||
int L, K;
|
||||
|
||||
scanf("%d %d %s", &L, &K, N); /* L == strlen(N) */
|
||||
for(int i = 0; i <= L - K; i++)
|
||||
{
|
||||
strncpy(n, N + i, K);
|
||||
if(iPrime(atoi(n)))
|
||||
{
|
||||
printf("%s", n);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf("404");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user