C with classes
This commit is contained in:
29
C/BasicSyntax/Cstring_test.cpp
Normal file
29
C/BasicSyntax/Cstring_test.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
int main(){
|
||||
char a[21][11];
|
||||
char sum[220]="";
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
for(int i=0;i<n;i++){
|
||||
scanf("%s",&a[i]);
|
||||
}
|
||||
int js=1;
|
||||
char tmp[11]="";
|
||||
while(js!=0){
|
||||
js=0;
|
||||
for(int i=0;i<n-1;i++){
|
||||
if(strcmp(a[i],a[i+1])<0){
|
||||
strcpy(tmp,a[i+1]);
|
||||
strcpy(a[i+1],a[i]);
|
||||
strcpy(a[i],tmp);
|
||||
js++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0;i<n;i++){
|
||||
strcat(sum,a[i]);
|
||||
}
|
||||
printf("%s",sum);
|
||||
return 0;
|
||||
}
|
||||
27
C/BasicSyntax/P1914 小书童——凯撒密码.cpp
Normal file
27
C/BasicSyntax/P1914 小书童——凯撒密码.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
void pwd(char ch[52]){
|
||||
for(int i=0;i<strlen(ch);i++){
|
||||
if(ch[i]!='z'){
|
||||
ch[i]++;
|
||||
}
|
||||
if(ch[i]=='z')
|
||||
ch[i]='a';
|
||||
}
|
||||
}
|
||||
int main(){
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
char a[52];
|
||||
scanf("%s",a);
|
||||
for(int i=0;i<strlen(a);i++){
|
||||
if(a[i]+n>=123)
|
||||
a[i]+=n-26;
|
||||
else{
|
||||
a[i]+=n;
|
||||
}
|
||||
|
||||
}
|
||||
printf("%s",a);
|
||||
return 0;
|
||||
}
|
||||
35
C/BasicSyntax/Pointer/difference_xp4_qxpq4.cpp
Normal file
35
C/BasicSyntax/Pointer/difference_xp4_qxpq4.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/*#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char *p[4] = {"Hello", "World", "C", "Language"};
|
||||
|
||||
printf("%s\n", p[1]); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>World
|
||||
printf("%c\n", *p[1]); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>W <20><>p[1]ָ<><D6B8>"World"<22><>*p[1]<5D><><EFBFBD><EFBFBD>'W'<27><>
|
||||
printf("%c\n", *(p[1] + 1)); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>o <20><>p[1] + 1 <20><> 'o' <20>ĵ<EFBFBD>ַ<EFBFBD><D6B7>
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int arr[2][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}};
|
||||
int (*p)[4] = arr;
|
||||
printf("%d\n", (*p)[2]); // <20><><EFBFBD><EFBFBD> 3<><33><EFBFBD><EFBFBD>Ϊ (*p) <20><><EFBFBD><EFBFBD> arr[0]<5D><><EFBFBD><EFBFBD> {1, 2, 3, 4}<7D><>Ȼ<EFBFBD><C8BB> [2] <20><>ʾ<EFBFBD><CABE><EFBFBD>ʵ<EFBFBD> 3 <20><>Ԫ<EFBFBD>ء<EFBFBD>
|
||||
//1<><31>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ַ 2<><32><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ֱ<EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//(*p)<29><>ţ<EFBFBD>ƣ<EFBFBD>ʲô<CAB2><C3B4><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>棬ʲô<CAB2><C3B4><EFBFBD><EFBFBD><EFBFBD>飩<EFBFBD><E9A3A9><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>飩<EFBFBD><E9A3A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԡ<EFBFBD>
|
||||
//(*p)[i]<5D><>p <20><>һ<EFBFBD><D2BB>ָ<EFBFBD><D6B8> <20><><EFBFBD>飨<EFBFBD><E9A3A8> int[4]<5D><><EFBFBD><EFBFBD>ָ<EFBFBD>롣<EFBFBD><EBA1A3><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD> p <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>鱾<EFBFBD><E9B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [i] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>Ԫ<EFBFBD>ء<EFBFBD>
|
||||
//*p[4]:p <20><>һ<EFBFBD><D2BB>ָ<EFBFBD><D6B8><EFBFBD>飬<EFBFBD><E9A3AC>5<EFBFBD><35>ָ<EFBFBD>룬*p[i]<5D>ǽ<EFBFBD><C7BD><EFBFBD>p[i]<5D><>ԭֵ
|
||||
//*(p + i)<29><>p <20><>һ<EFBFBD><D2BB>ָ<EFBFBD><D6B8>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>ص<EFBFBD>ָ<EFBFBD>롣ͨ<EBA1A3><CDA8>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> p + i <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB> i <20><>λ<EFBFBD>õ<EFBFBD>Ԫ<EFBFBD>ء<EFBFBD>
|
||||
//ָ<><D6B8><EFBFBD>е<EFBFBD>p[i]<5D><>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ*(p+i)
|
||||
char arr[2][4] = {"abc", "def"}; // 2 <20><> 4 <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
char (*p)[4] = arr; // p ָ<><D6B8> arr
|
||||
|
||||
printf("%s\n", p[0]); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>abc
|
||||
printf("%c\n", (*p)[1]); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b
|
||||
p++; // p <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> char[4] <20><><EFBFBD><EFBFBD>
|
||||
printf("%s\n", p[0]); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>def
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
18
C/BasicSyntax/Pointer/pointer_book_li8.27.cpp
Normal file
18
C/BasicSyntax/Pointer/pointer_book_li8.27.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
bool flag=false;
|
||||
int main(){
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
char dic[n][1000];
|
||||
char (* p)[1000] = dic;
|
||||
for(int i=0;i<n;i++){
|
||||
gets(dic[i]);
|
||||
}
|
||||
while(flag==false){
|
||||
for(int i=0;i<n;i++){
|
||||
if((* p))
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
40
C/BasicSyntax/Pointer/pointer_function_str1.cpp
Normal file
40
C/BasicSyntax/Pointer/pointer_function_str1.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
char str[201];
|
||||
/*char * add(char *str1,char *str2){
|
||||
int i=0;
|
||||
while(*str1!='\0'){
|
||||
str[i]=*str1;
|
||||
i++;str1++;
|
||||
}
|
||||
while(*str2!='\0'){
|
||||
str[i]=*str2;
|
||||
i++;str2++;
|
||||
}
|
||||
str[i]='\0';
|
||||
//printf("%s\n",str);
|
||||
//return str;
|
||||
}*/
|
||||
void add(char *str1,char *str2){
|
||||
int i=0;
|
||||
while(*str1!='\0'){
|
||||
str[i]=*str1;
|
||||
i++;str1++;
|
||||
}
|
||||
while(*str2!='\0'){
|
||||
str[i]=*str2;
|
||||
i++;str2++;
|
||||
}
|
||||
str[i]='\0';
|
||||
//printf("%s\n",str);
|
||||
//return str;
|
||||
}
|
||||
int main(){
|
||||
char a[100],b[100];
|
||||
//char * p= (char *)malloc(201*sizeof(char));
|
||||
scanf("%s%s",a,b);
|
||||
add(a,b);
|
||||
printf("%s",str);
|
||||
//free(p);
|
||||
return 0;
|
||||
}
|
||||
19
C/BasicSyntax/Pointer/pointer_test1.cpp
Normal file
19
C/BasicSyntax/Pointer/pointer_test1.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
void swap(int * a, int * b){
|
||||
int temp;
|
||||
temp = * a;
|
||||
* a = * b;
|
||||
* b = temp;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
scanf("%d%d",&a,&b);
|
||||
int *t1,*t2;
|
||||
t1=&a;
|
||||
t2=&b;
|
||||
swap(t1,t2);
|
||||
printf("%d %d\n",t1,t2);
|
||||
printf("%d %d\n",*t1,*t2);
|
||||
return 0;
|
||||
}
|
||||
47
C/BasicSyntax/Pointer/pointer_test_array.cpp
Normal file
47
C/BasicSyntax/Pointer/pointer_test_array.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
//<2F><><EFBFBD>⣺p<E2A3BA><70>&a<><61><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD>ֵֻ<D6B5><D6BB>ͨ<EFBFBD><CDA8>p=&a<><61>*p<><70>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>p<EFBFBD><70>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ϊ<EFBFBD>ڴ<EFBFBD><DAB4>е<EFBFBD>ֵ
|
||||
//const
|
||||
//#define x 0
|
||||
int x = 0;
|
||||
/*void change1(int *arr){
|
||||
*(arr+1) = -1;
|
||||
} */
|
||||
void change(int arr[5]){
|
||||
arr[1] = -1;
|
||||
}//Ч<><D0A7>һ<EFBFBD><D2BB>
|
||||
int main()
|
||||
{
|
||||
//ֻ<><D6BB>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ָ<EFBFBD>븳ֵ<EBB8B3><D6B5><EFBFBD><EFBFBD>ָ<EFBFBD>븳ֵ<EBB8B3><D6B5><EFBFBD>ǵ<EFBFBD>ַ<EFBFBD><D6B7>
|
||||
//<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
int * p;
|
||||
//p = &x; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>malloc<6F><63>ָ<EFBFBD><D6B8><EFBFBD>漴<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ַ
|
||||
//int a[5];//<2F><><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||
/*
|
||||
for(int i=0;i<5;i++){
|
||||
scanf("%d",&a[i]);
|
||||
}*/
|
||||
for(int i = 0;i < 5 ; i++) {
|
||||
p = &x;
|
||||
p++;
|
||||
}
|
||||
/*for(p = a; p < (a + 5) ; p++){
|
||||
scanf("%d",p);
|
||||
}*/
|
||||
p = &x;
|
||||
for(int i = 0 ; i < 5 ; i++){
|
||||
scanf("%d",p++);
|
||||
}
|
||||
//p = a;
|
||||
//* (p+2) = 0;
|
||||
//change(a);
|
||||
p = &x;
|
||||
for(int i=4 ; i >= 0 ; i--){
|
||||
printf("%d ",*(p+i));
|
||||
}
|
||||
/*printf("\n");
|
||||
for(int i=0;i<5;i++){
|
||||
printf("%d ",*(p+i));
|
||||
}*/
|
||||
// printf("%d",* p);
|
||||
return 0;
|
||||
}
|
||||
42
C/BasicSyntax/Pointer/pointer_test_pointer_arrary.cpp
Normal file
42
C/BasicSyntax/Pointer/pointer_test_pointer_arrary.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
//<2F><><EFBFBD><EFBFBD>һ
|
||||
/*int average(int *arr,int line,int row){
|
||||
int sum=0;
|
||||
for(int i=0;i<line*row;i++){
|
||||
sum+=*arr;
|
||||
*arr++;
|
||||
}
|
||||
return sum;
|
||||
} */
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int average(int (*arr)[3],int line,int row){
|
||||
int sum=0;
|
||||
for(int i=0;i<line;i++){
|
||||
for(int j=0;j<row;j++){
|
||||
sum+=*(*(arr+i)+j);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
int main(){
|
||||
int * p[3];
|
||||
int a[3][4];
|
||||
for(int i=0;i<3;i++){
|
||||
for(int j=0;j<4;j++){
|
||||
scanf("%d",&a[i][j]);
|
||||
}
|
||||
}
|
||||
for(int i=0;i<3;i++){
|
||||
p[i] = a[i];
|
||||
}
|
||||
//<2F><>2ά<32><CEAC><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>a[i]<5D><>i<EFBFBD>е<EFBFBD>ָ<EFBFBD>룬&a[i]<5D><>i<EFBFBD>е<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>룬<EFBFBD><EBA3AC>ͷ<EFBFBD><CDB7>
|
||||
for(int i=0;i<3;i++){
|
||||
for(int j=0;j<4;j++){
|
||||
printf("%d ",*(* (p+i)+j));
|
||||
}
|
||||
}
|
||||
//printf("%d",average(&a[0][0],3,4));
|
||||
printf("%d",average(&a,3,4));
|
||||
return 0;
|
||||
}
|
||||
28
C/BasicSyntax/Pointer/pointer_test_str1.cpp
Normal file
28
C/BasicSyntax/Pointer/pointer_test_str1.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
//strcmp //<2F><>ϼ<EFBFBD><CFBC>
|
||||
int main(){
|
||||
char str1[100],str2[100];
|
||||
char a[201];
|
||||
//char *sum;
|
||||
scanf("%s %s",str1,str2);
|
||||
int i=0;
|
||||
char *p1,*p2;
|
||||
p1=str1;
|
||||
p2=str2;
|
||||
while(*p1!='\0'){
|
||||
a[i]=*p1;
|
||||
i++;
|
||||
p1++;
|
||||
}
|
||||
a[i]='+';
|
||||
i++;
|
||||
while(*p2!='\0'){
|
||||
a[i]=*p2;
|
||||
i++;
|
||||
p2++;
|
||||
}
|
||||
a[i]='\0';
|
||||
*(a+1)='s';
|
||||
printf("%s",a);
|
||||
return 0;
|
||||
}
|
||||
30
C/BasicSyntax/Pointer/work_21.cpp
Normal file
30
C/BasicSyntax/Pointer/work_21.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
void sort(int *arr,int m){
|
||||
bool flag = false;
|
||||
while(flag == false){
|
||||
int js=0;
|
||||
for(int i = 0; i < m-1; i++){
|
||||
if(*(arr+i)>*(arr+i+1)){
|
||||
int temp;
|
||||
temp = *(arr+i+1);
|
||||
* (arr+i+1) = * (arr+i);
|
||||
* (arr+i) = temp;
|
||||
js++;
|
||||
}
|
||||
}
|
||||
if(js==0) flag=true;
|
||||
}
|
||||
}
|
||||
int main(){
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
int a[n];
|
||||
for(int i = 0; i < n; i++){
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
sort(a,n);
|
||||
for(int i = 0; i < n; i++){
|
||||
printf("%d ",a[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
59
C/BasicSyntax/Structure/STRUCTURE_test1.cpp
Normal file
59
C/BasicSyntax/Structure/STRUCTURE_test1.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define length sizeof(student)
|
||||
union age1{
|
||||
int age2;
|
||||
char c;
|
||||
}a;
|
||||
struct student{
|
||||
int num;
|
||||
char name[100];
|
||||
char sex[100];
|
||||
union blast{
|
||||
int age;
|
||||
char f;
|
||||
}category;
|
||||
struct student * next;
|
||||
};
|
||||
int main(){
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
struct student temp,* p,* head,* p2;
|
||||
printf("Enter By NUMBER NAME SEX AGE\n");
|
||||
p = (struct student *)malloc(sizeof(struct student));
|
||||
//head = (struct student *)malloc(sizeof(struct student));
|
||||
//p2 = (struct student *)malloc(sizeof(struct student));
|
||||
|
||||
/*for(int i = 0; i < n; i++){
|
||||
scanf("%d%s%s%d",&a[i].num,a[i].name,a[i].sex,&a[i].age);
|
||||
a[i].next = (struct student *)&a[i];
|
||||
}
|
||||
<09><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>struct<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>洢<EFBFBD><E6B4A2><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
||||
*/
|
||||
head = p;
|
||||
int i = 1;
|
||||
while(i <= n){
|
||||
scanf("%d%s%s%d",&p->num,p->name,p->sex,&p->category.age);
|
||||
if(i == n)
|
||||
{
|
||||
p->next = NULL;
|
||||
break;
|
||||
}
|
||||
else p2 = (struct student *)malloc(sizeof(struct student));
|
||||
p->next = p2;
|
||||
p = p2;
|
||||
i++;
|
||||
}
|
||||
p = head;
|
||||
while(p!=NULL){
|
||||
printf("The age of %s is %d, he is a %s\n",p->name,p->category.age,p->sex);
|
||||
p2 = p;
|
||||
p = p->next;
|
||||
free(p2);
|
||||
}
|
||||
printf("\n");
|
||||
//free(p);
|
||||
//free(head);
|
||||
//free(p2);
|
||||
return 0;
|
||||
}
|
||||
7
C/BasicSyntax/Structure/Structure_Union.cpp
Normal file
7
C/BasicSyntax/Structure/Structure_Union.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
C/BasicSyntax/Structure/Union_test1.cpp
Normal file
14
C/BasicSyntax/Structure/Union_test1.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
union category{
|
||||
int a;
|
||||
char b;
|
||||
double c;
|
||||
};
|
||||
|
||||
int main(){
|
||||
union category arse;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
C/BasicSyntax/Untitled-1.c
Normal file
10
C/BasicSyntax/Untitled-1.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(){
|
||||
char n[200];
|
||||
getline(n);
|
||||
printf("Hello, world %s",n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
C/BasicSyntax/blaset/1.cpp
Normal file
14
C/BasicSyntax/blaset/1.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
int n;
|
||||
cin >> n;
|
||||
int* a = new int [n];
|
||||
int js = 0;
|
||||
for(int i = 0;i < n;i++){
|
||||
cin >> a[i];
|
||||
js += a[i];
|
||||
}
|
||||
cout << js <<endl;
|
||||
return 0;
|
||||
}
|
||||
BIN
C/BasicSyntax/blaset/1.o
Normal file
BIN
C/BasicSyntax/blaset/1.o
Normal file
Binary file not shown.
26
C/BasicSyntax/ctest.cpp
Normal file
26
C/BasicSyntax/ctest.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
/*
|
||||
printf<EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
%5d:<3A><><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD>Ҷ<EFBFBD><D2B6>룬<EFBFBD>ո<EFBFBD><D5B8><EFBFBD>
|
||||
%05d(%.5d)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD>Ҷ<EFBFBD><D2B6>룬0<EBA3AC><30>
|
||||
%-5d<35><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬<EFBFBD>ո<D5B8><F1B2B9A1><EFBFBD><EFBFBD><EFBFBD>д%-.5d
|
||||
|
||||
printf<EFBFBD><EFBFBD>%c,%s<><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
%.2s<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>λ
|
||||
*/
|
||||
int main(){
|
||||
double a=2,b=4;
|
||||
a/=3;
|
||||
b/=7;
|
||||
printf("double:\na = %04.2f%%, b = %55.50f%%\n",a,b);
|
||||
printf("a = %07f, b = %08f\n",a,b);
|
||||
int c=345;
|
||||
printf("int:\nc = %.6d\n",c);
|
||||
printf("c = %05d\n",c);
|
||||
printf("c = %-5d\n",c);
|
||||
double f=123456;
|
||||
printf("e:\nf = %10.2e\n",f);
|
||||
char d[]="canyoukissmyass";
|
||||
printf("string:\n%.2s\n",d);
|
||||
return 0;
|
||||
}
|
||||
44
C/BasicSyntax/fileiostream/file_test1.cpp
Normal file
44
C/BasicSyntax/fileiostream/file_test1.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
//f means file
|
||||
int main(){
|
||||
FILE * fp, *fout;
|
||||
fp = fopen("test.dat","rb");
|
||||
if(fp == NULL){
|
||||
printf("Damn!");
|
||||
exit(0);
|
||||
}
|
||||
char arr[100];
|
||||
int i=0;
|
||||
while(fgetc(fp)!=EOF){
|
||||
fseek(fp, -1, SEEK_CUR);
|
||||
arr[i] = fgetc(fp);
|
||||
i++;
|
||||
}
|
||||
arr[i] = '\0';
|
||||
//printf("%s",arr);
|
||||
/*
|
||||
for(int i = 0; i < strlen(arr) ; i++ ){
|
||||
scanf
|
||||
}*/
|
||||
// fput();
|
||||
fout = fopen("fout.dat","ab");
|
||||
for(int i = 0; i < strlen(arr) ; i++){
|
||||
fputc(arr[i], fout);
|
||||
}
|
||||
FILE *f1;
|
||||
f1 = fopen("fout.dat","rb");
|
||||
while(fgetc(f1)!=EOF){
|
||||
//putchar(arr[i]);
|
||||
fseek(f1,-1,1);
|
||||
putchar(fgetc(f1));
|
||||
Sleep(50);
|
||||
}
|
||||
|
||||
fclose(fout);
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
C/BasicSyntax/fileiostream/fout.dat
Normal file
1
C/BasicSyntax/fileiostream/fout.dat
Normal file
@@ -0,0 +1 @@
|
||||
Hello,World!Hello,World!Hello,World!Hello,World!Hello,World!Hello,World!
|
||||
1
C/BasicSyntax/fileiostream/test.dat
Normal file
1
C/BasicSyntax/fileiostream/test.dat
Normal file
@@ -0,0 +1 @@
|
||||
Hello,World!
|
||||
15
C/BasicSyntax/stringctest.cpp
Normal file
15
C/BasicSyntax/stringctest.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
double sum=0,tmp=1;
|
||||
/*while((1/tmp)>=1e-6){
|
||||
sum+=1/tmp;
|
||||
sum-=1/(tmp+2);
|
||||
tmp+=4;
|
||||
printf("%.15f\n",1/(tmp+2));
|
||||
}
|
||||
printf("%.15f",4*sum);*/
|
||||
printf("%.15f\n",0.123e-6);
|
||||
return 0;
|
||||
}
|
||||
13
C/BasicSyntax/test.cpp
Normal file
13
C/BasicSyntax/test.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
int s=0;
|
||||
for(int i=1;i<=n;i++){
|
||||
s+=i;
|
||||
}
|
||||
cout<<s<<endl;
|
||||
return 0;
|
||||
}
|
||||
6
C/BasicSyntax/未命名6.cpp
Normal file
6
C/BasicSyntax/未命名6.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int main(){
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user