#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <math.h>
typedef struct {
char dm[5];
char mc[11];
int dj;
int sl;
long je;
}PRO;
//-----------------1---------------//
int isP(int m) {
int i;
for (i = 0; i < sqrt(m); i++)
if (m%i == 0) return 0;
return 1;
}
void ques01(int m, int k, int xx[]) {
int i, j = 0;
for (i = m+1; j < k; i++)
if (isP(i)) xx[j++] = i;
}
//-----------------1---------------//
//-----------------2---------------//
#define MAX 200
int a[MAX], b[MAX], cnt = 0;
void ques02() {
int c1, c2, c3, c4;
int i, j, temp;
for (i = 0; i < MAX; i++) {
c1 = a[i]%10;
c2 = a[i]%100/10;
c3 = a[i]%1000/100;
c4 = a[i]/1000;
if (c1%2==0 && c2%2==0 && c3%2==0 && c4%2==0)
b[cnt++] = a[i];
}
for (i = 0; i < cnt; i++)
for (j = i+1; j < cnt; j++)
if (b[i] < b[j])
{ temp = b[i]; b[i] = b[j]; b[j] = temp; }
}
//-----------------2---------------//
//-----------------3---------------//
char xx[50][80];
int maxline = 0;
void ques03() {
int i, j;
char *p, temp[80];
for (i = 0; i < maxline; i++) {
while (1) {
p = strchr(xx[i], 'o');
if (!p) break;
strcpy(temp, p+1);
*p = 0;
strcat(temp, xx[i]);
strcpy(xx[i], temp);
}
}
}
//-----------------3---------------//
//-----------------4---------------//
char xx[50][80];
int maxline = 0;
int isLetter(char c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
void ques04() {
int i, j;
char *p, *q, temp[80];
for( i = 0; i < maxline; i++ ) {
temp[0] = 0;
while (1) {
for (q = xx[i]+strlen(xx[i])-1; q >= xx[i] && !isLetter(*q); q--);
for (p = q; p > xx[i] && isLetter(*(p-1)); p--);
if (p < xx[i] || q < xx[i]) break;
*(q+1) = 0;
strcat(temp, p);
strcat(temp, " ");
*p = 0;
}
strcpy(xx[i], temp);
}
}
//-----------------4---------------//
//-----------------5---------------//
#define MAX 200
int aa[MAX], bb[10];
void ques05() {
int i, j, k, temp;
for (i = 0; i < MAX; i++)
for (j = i+1; j < MAX; j++)
if (aa[i]%1000 > aa[j]%1000 || (aa[i]%1000 == aa[j]%1000 && aa[i] < aa[j]))
{temp = aa[i]; aa[i] = aa[j]; aa[j] = temp;}
for (i = 0; i < 10; i++)
bb[i] = aa[i];
}
//-----------------5---------------//
//-----------------7---------------//
#define MAX 100
PRO sell[MAX];
void ques07() {
int i, j, len = sizeof(PRO);
PRO temp;
for (i = 0; i < MAX; i++)
for (j = i+1; j < MAX; j++) {
if (strcmp(sell[i].dm, sell[j].dm)<0 || (strcmp(sell[i].dm, sell[j].dm)==0 && sell[i].je < sell[j].je))
{
memcpy(&temp, &sell[i], len);
memcpy(&sell[i], &sell[j], len);
memcpy(&sell[j], &temp, len);
}
}
}
//-----------------7---------------//
//-----------------8---------------//
char xx[50][80];
int maxline = 0;
char encrypt(char p) {
char x = p*11%256;
if (x<=32 || x>130) return p;
else return x;
}
void ques08() {
int i, j;
char x;
for (i = 0; i < maxline; i++)
for (j = 0; j < strlen(xx[i]); j++)
xx[i][j] = encrypt(xx[i][j]);
}
//-----------------8---------------//
//-----------------9---------------//
char xx[50][80];
int maxline = 0;
void ques09() {
int i, j, k;
char temp;
for (i = 0; i < maxline; i++ ) {
for (j = 0; j < strlen(xx[i]); j++ ) ;
for (k = j+1; k < strlen(xx[i]); k++ ) ;
if ( xx[i][j] < xx[i][k] )
{ temp = xx[i][j]; xx[i][j] = xx[i][k]; xx[i][k] = temp; }
}
}
//-----------------9---------------//
//-----------------10--------------//
char xx[50][80];
int maxline = 0;
char nextLetter( char c ) {
if ( c >= 'a' && c < 'z' ) return c+1;
if ( c == 'z' ) return 'a';
return c;
}
void ques10() {
int i, j;
for ( i = 0; i < maxline; i++ )
for ( j = 0; j < strlen(xx[i]); j++ )
xx[i][j] = nextLetter(xx[i][j]);
}
//-----------------10--------------//
//-----------------11--------------//
char nextLetter( char c ) {
if ( (c >= 'a' && c < 'z') || (c >= 'A' && c < 'Z') ) return c+1;
else if ( c == 'z' ) return 'a';
else if ( c == 'Z' ) return 'A';
else return c;
}
void ques11(char *s) {
int i;
for (i = 0; i < strlen(s); i++)
s[i] = f3(s[i]);
}
//-----------------11--------------//
//-----------------14--------------//
#define MAX 200
int a[MAX], b[MAX], cnt = 0;
void ques14() {
int i, k, temp;
for ( i = 0; i < MAX-5; i++ )
if (a[i]%2 != 0 && a[i] > a[i+1] && a[i] > a[i+2] && a[i] > a[i+3] && a[i] > a[i+4] && a[i] > a[i+5] )
b[cnt++] = a[i];
for ( i = 0; i < cnt; i++ )
for ( k = i+1; k < cnt; k++ )
if ( b[i] > b[k] )
{ temp = b[i]; b[i] = b[k]; b[k] = temp; }
}
//-----------------14--------------//
//-----------------15--------------//
#define MAX 200
int a[MAX], b[MAX], cnt = 0;
void ques15() {
int i, j, k, c1, c2, c3, c4;
for ( i = 0; i < MAX; i++ ) {
c1 = a[i]/1000;
c2 = a[i]%1000/100;
c3 = a[i]%100/10;
c4 = a[i]/10;
if ( c1 <= c2 && c2 <= c3 && c3 <= c4 && a[i]%2 == 0 )
b[cnt++] = a[i];
}
}
//-----------------15--------------//
//-----------------17--------------//
char xx[50][80];
int maxline = 0;
void ques17() {
int i, j, len, k;
char c;
for (i = 0; i < maxline; i++){
c = xx[i][0];
for (j = 0; j < strlen(xx[i])-1; j++) {
xx[i][j] += xx[i][j+1];
}
xx[i][j] += c;
len = strlen(xx[i]);
k = len/2;
for (j = 0; j < k; j++)
{ c = xx[i][j]; xx[i][j] = xx[i][len - j - 1]; xx[i][len - j - 1] = c; }
}
}
//-----------------17--------------//
//-----------------19--------------//
int ques19(char *str, char *substr) {
int i, len = strlen(str), sum = 0;
for (i = 0; i < len-1; i++) {
if (str[i] == substr[0] && str[i+1] == substr[1]) sum++;
}
return sum;
}
int ques19_ans2(char *str, char *substr) {
int i, j, len1 = strlen(str), len2 = strlen(substr), sum = 0;
for (i = 0; i <= len1 - len2; i++) {
for (j = 0; j < len2; j++) {
if (str[i] != substr[j]) break;
}
if (j == len2) sum++;
}
return sum;
}
//-----------------19--------------//
//-----------------20--------------//
int ques20(int t) {
int a = 0, b = 1;
while (1) {
if (a>t) return a;
if (b>t) return b;
a = a+b;
b = a+b;
}
}
//-----------------20--------------//
//-----------------21--------------//
float ques21() {
float x0, x1 = 0.0;
while(1) {
x0 = x1;
x1 = cos(x0);
if (x0-x1 < 1e-6) return x1;
}
}
//-----------------21--------------//
//-----------------22--------------//
double ques22(int n) {
int i, sum = 0;
for (i = 1; i < n; i++) {
if (i%3==0 && i%7==0) sum+=i;
}
return sqrt(sum);
}
double ques22_ans2(int n) {
return sqrt((n/21)*(n/21+1)/2*21);
}
//-----------------22--------------//
//-----------------23--------------//
#define MAX 200
float xx[MAX];
int N = 0;
double aver = 0.0;
double sumint = 0.0;
double sumdec = 0.0;
void ques23() {
int i;
float sum = 0.0;
for (i = 0; i < N; i++) {
sum += xx[i];
sumint += (int)xx[i];
sumdec += xx[i] - (int)xx[i];
}
aver = sum / N;
}
void ques23_ans2() {
int i;
for (i = 0; i < N; i++) {
aver += xx[i];
sumint += (int)xx[i];
}
sumdec = aver - sumint;
aver /= N;
}
//-----------------23--------------//
//-----------------24--------------//
int ques24(int bb[]) {
int index = 0, i, c1, c2, c3, d;
for (i = 100; i < 1000; i++) {
c1 = i%10;
c2 = i%100/10;
c3 = i/100;
d = (int)sqrt(i);
if (i==d*d && (c1==c2 || c2==c3 || c1==c3))
bb[index++] = i;
}
}
int ques24_ans2(int bb[]) {
int index = 0, i, c1, c2, c3, d;
for (d = 10; d <= 31; d++) {
i = d*d;
c1 = i%10;
c2 = i%100/10;
c3 = i/100;
if (i==d*d && (c1==c2 || c2==c3 || c1==c3))
bb[index++] = i;
}
}
//-----------------24--------------//
//-----------------25--------------//
int ques25(long m) {
int i, len;
char p[10], temp;
long m2;
ltoa(m, p, 10);
len = strlen(p);
for (i = 0; i < len/2; i++) {
temp = p[i]; p[i] = p[len-i-1]; p[len-i-1] = temp;
}
m2 = atol(p);
return m==m2;
}
int ques25_ans2(long n) {
int i, len;
char temp[20];
ltoa(n, temp, 10);
len = strlen(temp);
for (i = 0; i < len/2; i++) {
if (temp[i] != temp[len - i - 1]) return 0;
}
return 1;
}
//-----------------25--------------//
//-----------------33--------------//
#define MAX 1000
int xx[MAX], odd = 0, even = 0;
double ave1 = 0.0, ave2 = 0.0, totfc = 0.0;
void ques33() {
int i;
for (i = 0; i < MAX; i++) {
if (xx[i]%2 == 0) { even++; ave2 += xx[i]; }
else ave1 += xx[i];
}
ave1 /= MAX-even;
ave2 /= even;
for (i = 0; i < MAX; i++) {
if (xx[i]%2==0)
totfc += (xx[i] - ave2)*(xx[i] - ave2);
}
totfc /= even;
}
//-----------------33--------------//
//-----------------34--------------//
int cnt, sum;
void ques34() {
int i, c1, c2, c3;
for (i = 100; i < 1000; i++)
if (isP(i)) { //这个函数是第一题里的
c1 = i%10;
c2 = i%100/10;
c3 = i/100;
if ((c1+c2)%10 == c3) { cnt++; sum+=i; }
}
}
//-----------------34--------------//
//-----------------35--------------//
int b[3];
void ques35() {
int n, A = 1, B = 1, C, sum = A+B;
b[0] = b[1] = b[2] = 0;
for (n = 3; ; n++) {
//第n次计算,求An和Sum = A1+...+An
C = A + 2*B;
//把计算出来的An加到累加器
sum += C;
//如果满足条件,且记录器从未记录过
if (sum>=100 && b[0]==0) b[0] = n-1;
if (sum>=1000 && b[1]==0) b[1] = n-1;
if (sum>=10000) { b[2] = n-1; break; }
//向后递推
A = B;
B = C;
}
}
void ques35_ans2(void){
int n, x = 1, y = 1, z, sum0, sum;
sum0 = sum = x+y;
b[0] = b[1] = b[2] = 0;
for (n = 3; ;n++) {
//第n次计算,已知Sum0 = A1+...+An-1,求An和Sum = A1+...+An
z = x + 2*y;
//把计算出来的An加到累加器
sum = sum0 + z;
//如果满足条件
if (sum0<100 && sum>=100) b[0] = n-1;
if (sum0<1000 && sum >= 1000) b[1] = n-1;
if (sum0<10000 && sum >= 10000) {b[2] = n-1; break;}
//如果不满足则向后递推
x = y;
y = z;
sum0 = sum;
}
}
//-----------------35--------------//
//-----------------39--------------//
char xx[100][11];
int yy[10];
void ques39() {
int i, j;
for (i = 0; i < 10; i++) yy[i] = 0;
for (i = 0; i < 100; i++) {
if (strcmp(xx[i], "1111111111") == 0) continue;
if (strcmp(xx[i], "0000000000") == 0) continue;
for (j = 0; j < 10; j++)
if (xx[i][j] == '1') yy[j]++;
}
}
//-----------------39--------------//
//-----------------41--------------//
int cnt, sum;
void ques41() {
int i, j;
cnt = 0, sum = 0;
for (i = 100; i < 1000; i++)
for (j = 1000; j < 10000; j++)
if (i*3 == j*2) {
if (i%100/10 == j%1000/100 && j%100/10 == j/1000) {
cnt++;
sum += i+j;
}
}
}
//-----------------41--------------//
//-----------------43--------------//
char xx[20][80];
void ques43() {
int i, j, k;
char temp;
for (i = 0; i < 20; i++)
for (j = 1; j < strlen(xx[i]); j+=2)
for (k = j+2; k < strlen(xx[i]); k+=2)
if (xx[i][j] > xx[i][k])
{ temp = xx[i][j]; xx[i][j] = xx[i][k]; xx[i][k] = temp; }
}
//-----------------43--------------//
//-----------------44--------------//
char xx[20][80];
void ques44() {
int i, j, k, len;
char temp;
for (i = 0; i < 20; i++) {
len = strlen(xx[i]);
for (j = 0; j < len/2; j++)
for (k = j+1; k < len/2; k++)
if (xx[i][j] < xx[i][k])
{ temp = xx[i][j]; xx[i][j] = xx[i][k]; xx[i][k] = temp; }
for (j = 0; j < len/2; j++)
{ temp = xx[i][j]; xx[i][j] = xx[i][(len+1)/2 - j]; xx[i][(len+1)/2 - j] = temp; }
}
}
//-----------------44--------------//
//-----------------50--------------//
char xx[20][80];
void ques50(){
int i, j, k, len;
char temp;
for (i = 0; i < 20; i++){
len = strlen(xx[i]);
for (j = 0; j < len/2; j++){
for (k = j+1; k < len/2; k++){
if (xx[i][j] < xx[i][k]){
temp = xx[i][j]; xx[i][j] = xx[i][k]; xx[i][k] = temp;
}
}
}
for (j = 0; j < len/2; j++){
temp = xx[i][j]; xx[i][j] = xx[i][(len+1)/2+i]; xx[i][(len+1)/2+i] = temp;
}
}
}
//-----------------50--------------//
//-----------------57--------------//
#define N 100
#define S 1
#define M 10
int p[100], n = N, s = S, m = M;
void ques57 (){
int i, j, k = -1, a[100];
for (i = 0; i < N; i++) a[i] = 1;//1表示在圈内,0表示不在
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
do {
k++;
if (k==N) k = 0;
}while(!a[k]);
//编号为k的人报数,报的是j
}
//编号为k的人报了M,此人出列
p[i] = k+1;
a[k] = 0;
}
}
//-----------------57--------------//
//-----------------58--------------//
char xx[100][11];
int yy[10];
void ques58() {
int i, j, sum;
for (i = 0; i < 10; i++) yy[i] = 0;
for (i = 0; i < 100; i++) {
sum = 0;
for (j = 0; j < 10; j++) sum++;
if ( sum > 5 ) {
for (j = 0; j < 10; j++)
if (xx[i][j] == '1') yy[j]++;
}
}
}
//-----------------58--------------//
//-----------------60--------------//
typedef struct {
int x1, x2, x3;
}Data;
Data aa[200], bb[200];
int ques60() {
int i, j, cnt = 0, len = sizeof(Data);
Data temp;
for (i = 0; i < 200; i++)
if (aa[i].x1 + aa[i].x3 < aa[i].x2)
memcpy(&bb[cnt++], &aa[i], len);
for (i = 0; i < cnt; i++)
for (j = i+1; j < cnt; j++)
if (bb[i].x2 + bb[i].x3 < bb[j].x2 + bb[j].x3) {
memcpy(&temp, &bb[i]);
memcpy(&bb[i], &bb[j]);
memcpy(&bb[j], temp);
}
}
//-----------------60--------------//
//-----------------63--------------//
void ques63(char *s){
int i, j, len = strlen(s);
char temp;
temp = s[0];
for (i = 1; i < len; i++) s[i-1] = s[i];
s[len - 1] = temp;
}
//-----------------63--------------//
//-----------------66--------------//
int cnt, sum;
void ques66() {
int i, j, flag = 1;
cnt = sum = 0;
for (i = 800; i > 500; i--) {
if (isP(i)) {
cnt++;
if (flag) sum += i;
else sum -= i;
flag = - flag;
}
}
}
//-----------------66--------------//
//-----------------90--------------//
void ques90(int a[10][9]) {
int b[9];
int i, j, k, len = sizeof(b);
for (i = 0; i < 10; i++) {
memcpy(&b, &a[i], len);
k = 0;
for (j = 8; j > 0; j--)
if (b[j] < b[0]) a[i][k++] = b[j];
a[i][k++] = b[0];
for (j = 0; j < 9; j++)
if (b[j] > b[0]) a[i][k++] = b[j];
}
}
//-----------------90--------------//
//-----------------92--------------//
#define N 200
int max, cnt, xx[N];
float pj;
void ques92() {
int i, j, m = 0;
max = MAXINT;
for (i = 0; i < N; i++) {
if (max < xx[i]) {
max = xx[i];
cnt = 0;
} else if (max == xx[i])
cnt++;
if (xx[i]%3 == 0 || xx[i]%7 == 0) {
pj += xx[i];
m++;
}
pj /= m;
}
}
//-----------------92--------------//
posted on 2005-02-12 00:15
Brian Sun 阅读(353)
评论(0) 编辑 收藏 所属分类:
软件