week_2_day1_7.7 Monday
Use character arrays for letter case conversions
#include <stdio.h>
void Desc (char *a, int n)
{
char *i = A;
int x = 0;
for (x = 0; x < n; x + +)
{
if (*i >= 97)
*i-=32;
i++;
}
}
int main (void)
{
void Desc (char *num, int n);//must be declared inside the function
Char num[100], A;
int i = 0, k = 0;
while ((A = GetChar ()) = ' \ n ') {
Num[i] = A;
i++;
}
Desc (num,i);
for (k = 0; k < i; K + +) {
printf ("%c", Num[k]);
}
return 0;
}
Large number Addition
#include <stdio.h>
int main (int argc, const char * argv[])
{
int a[1001] = {},b[1001] = {}, c[1001] = {};
int I, j= 0, k1 = 0, k2 = 0, count1 = 0, count2 = 0;
Char ch, ch1 = ' 0 ';
for (i = 1; (ch = getchar ())! = "; i + +) {
j = ch-ch1;
A[i] = j;
}//first big number
K1 =i-1;
for (i = 1; (ch = getchar ())! = ' \ n '; i + +) {
j = ch-ch1;
B[i] = j;
}//second Big number
K2 = i-1;
if (K1 > K2) {
Count1 = K1;
Count2 = K2;
}
else{count1 = K2;
Count2 = K1;
}
for (i = count1; i > 0; I--, K1--, K2--) {//Add
if (K2 <= 0)
C[i] + = a[k1];//to determine if the smaller number has been added
else if (K1 <= 0)
C[i] + = A[k2];
else{
C[i] + = (A[k1] + b[k2]);
if (C[i] > 9)
{
C[i]%= 10;
C[i-1] = 1;//whether rounding
}
}
}
if (c[0] = = 1)
printf ("%d", c[0]);
for (i = 1; I <= count1; i + +)
printf ("%d", c[i]);
printf ("\ n");
return 0;
}
The number of n! is not very understanding.
#include <stdio.h>
#include <math.h>
int factorial (int n)
{
Long a[10000];
int i,j,c,m=0,w,l = 0;
A[0]=1;
for (i=1;i<=n;i++)
{
c=0;
for (j=0;j<=m;j++)
{
A[j]=a[j]*i+c;
c=a[j]/10000;
a[j]=a[j]%10000;
}
if (c>0) {m++;a[m]=c;}
}
W=M*4+LOG10 (A[m]) +1;
printf ("\n%ld", A[m]);
for (i=m-1;i>=0;i--)
printf ("%4.4ld\n", A[i]);
Return w;
}
int main (int argc, const char * argv[])
{
int x;
scanf ("%d", &x);
X=factorial (x);
printf ("%d", x);
return 0;
}
The distribution scheme of tug-of-war competition
is to use random functions to determine the person in that team, and then compare the team and the overall weight difference is small, then output him.
#include <stdio.h>
#include <stdlib.h>
#include <sys/_types/_mode_t.h>
int swap (int *a, int j);
int swap (int *a, int j)
{
int min = 0, b, s = 0, sum = 0;
int c[100] = {};
for (int i = 0; i < J; i + +) {
Sum + = A[i];
}//total number of body weight
printf ("Total weight:%d\n", sum);
for (int h = 0; h < J; H + +)
{
C[H] =-1;
}
for (int i = 0; I < 10000; i + +)
{
for (int n = 0; n < J/2; n + +)
{
Aa:
b = ABS (Arc4random ()% (j));
for (int h = 0; h < n; H + +)
{
if (c[h] = = b)
{
Goto AA;
}
}
C[n] = b;
s + = a[b];
}
for (int h = 0; h < J; H + +)
{
C[H] =-1;
}//reset saved already useful data
if (ABS (SUM/2-min) > abs (SUM/2-s)) {
Min = s;
}
s = 0;
}
return min;
}
int main (void)
{
int A, ch[100],sum = 0;
printf ("Please enter the total number of tug-of-war competitions:");
scanf ("%d", &a);
for (int i = 0; i < A; i + +)
{
printf ("Please enter%d person:", i+1);
scanf ("%d", &ch[i]);
}
int min = swap (ch, a);
for (int i = 0; i < A; I + +) {
Sum + = Ch[i];
}
printf ("Comparatively light troop:%d\n", Min);
printf ("Heavier Troop:%d\n", sum-min);
printf ("%d\n", A, j);
return 0;
}
Loop N to the right for a bit and then output
#include <stdio.h>
int ch[32] = {}, ch_l[32] = {};
void Printfarry (int *a, int b);//output array
int * Del_num (long a);//decomposition number is 2 binary deposit into array
int * toright (int * p, int m);//Move Right
int to_arry_num (int k);//each array should be added to the power of 2 K
int to_sum (int *p, int h);//The converted number of the last output
void Printfarry (int *a, int b) {
int i = 0;
for (i = 0; I < b; i + +) {
printf ("%d\t", A[i]);
}
}
int * Del_num (long a) {
int i = 0;
for (i = 0; a > 0; i + +)
{
if (a%2 = = 0) {
ch[31-i] = 0;
}
else{
ch[31-i] = 1;
}
A/= 2;
}
return ch;
}
int * toright (int * p, int m)
{
int i = 0, k = +, J;
for (i = 31-m; I >=0; K--, I--)
{
CH_L[K] = P[i];
}
for (j = n; j >31-m; K--, J-) {
CH_L[K] = P[j];
}
return ch_l;
};
int to_arry_num (int k) {
int i = 0, S=1;
for (; I < K; i + +) {
S *= 2;
}
return s;
}
int to_sum (int *p, int h) {
int sum = 0, i = 0;
for (i = 0; i < h; i + +)
{
if (p[i] = = 1)
{
Sum + = To_arry_num (31-i);
}
}
return sum;
}
int main (int argc, const char * argv[])
{
Long A;
int *p, m = 0;
scanf ("%ld", &a);
scanf ("%d", &m);
printf ("%ld\n", a);
if (A = =-1) {
printf ("-1");
}
Else
{
P =del_num (a);//decomposition number is 2 binary
P=toright (P, m);
Printfarry (p,32);
printf ("\ n");
A = To_sum (P, 32);
printf ("%ld\n", a);
}
return 0;
}
Loop left N-bit
#include <stdio.h>
int ch[32] = {}, ch_l[32] = {};
void Printfarry (int *a, int b);
int * Del_num (long a);
int * TOLEFT (int * p, int m);
int to_arry_num (int k);
int to_sum (int *p, int h);
void Printfarry (int *a, int b) {
int i = 0;
for (i = 0; i < b; i + +) {
printf ("%d", a[i]);
}
}
int * Del_num (long a) {
int i = 0;
for (i = 0; a > 0; i + +)
{
if (a%2 = = 0) {
ch[31-i] = 0;
}
else{
ch[31-i] = 1;
}
A/= 2;
}
return ch;
}
int * TOLEFT (int * p, int m)
{
int i = 0, k = 31-m;
for (i = +; k = = 0; k--, I-)
{
CH_L[K] = P[i];
}
for (k = 31-m; I >= 0; k--, I--) {
CH_L[K] = P[i];
}
return ch_l;
};
int to_arry_num (int k) {
int i = 0, S=1;
for (; i < k; i + +) {
S *= 2;
}
return s;
}
int to_sum (int *p, int h) {
int sum = 0, i = 0;
for (i = 0; i < h; i + +)
{
if (p[i] = = 1)
{
Sum + = To_arry_num (31-i);
}
}
return sum;
}
int main (int argc, const char * argv[])
{
Long A;
int *p, m = 0;
scanf ("%ld", &a);
scanf ("%d", &m);
printf ("%ld\n", a);
if (A = =-1) {
printf ("-1");
}
Else
{
if (m! = 32)
{
P =del_num (a);//decomposition number is 2 binary
P=toleft (P, m);
Printfarry (p,32);
printf ("\ n");
A = To_sum (P, 32);
printf ("%ld\n", a);
}else
{
printf ("%d", a);
}
}
return 0;
}
A linked list that is sorted by ID is implemented and the nodes in the linked list are initialized in an orderly manner, then a new node is inserted into the linked list, and after the insert is completed, the list is not broken.
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define LEN sizeof (struct stu)
struct Stu {
int id;
Char a[1];
struct Stu *next;
};
int n;
struct stu* C (void) {//Create linked list
struct Stu *head;
struct Stu *p1,*p2;
n = 0;
P1 =p2 = (struct stu*) malloc (LEN);
scanf ("%d%c", &p1->id,&p1->a[0]);
head = NULL;
do{
n + = 1;
if (n = = 1) head = p1;
else P2->next = p1;
P2 = p1;
if (p2->a[0] = = ' \ n ')
Break
P1 = (struct Stu *) malloc (LEN);
scanf ("%d%c", &p1->id,&p1->a[0]);
P2-next = NULL;
}while (1);
return (head);
}
int main (int argc, const char * argv[])
{
struct Stu *p, *p3, *P4,*P5;
p = C ();
P5 = P;
p3= (struct Stu *) malloc (LEN);
scanf ("%d", &p3->id);
p4=p->next;
while (1) {
if ((P4->id) < (P->id)) {
if (p3->id >p4->id && p3->id < P->id)
{
P3->next = P4;
P->next = p3;//Inserts a pointer
Break
}
Else
{
p = P4;
P4 = p4->next;//Move to the back one address
}
}
if (P4->id > P->id)
{
if (P3->id > P->id && p3->id < P4->id)
{
P3->next = P4;
P->next = p3;//Move to the back one address
Break
}
Else
{
p = p4;//Move to the back one address
P4 = p4->next;
}
}
}
while (P5! = NULL) {
printf ("%d", p5->id);
P5 = p5->next;
}
printf ("\ n");
return 0;
}