NOIP(七)

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 /**
 5     文件操作 
 6     练习:读取2组测试数据
 7     测试点1(in.txt):
 8     输入(in.txt):    5
 9                     2 3 5 7 6
10     输出(out.txt):    7
11     
12     测试点2(in2.txt):
13     输入(in2.txt):    6
14                     1 7 8 9 101 100
15     输出(out2.txt):101     
16 */
17 int main(){
18     freopen("in.txt","r",stdin);
19     freopen("out.txt","w",stdout);
20     int temp , sum = 0;
21     while(scanf("%d",&temp) == 1){//只要读取的数据不到末行 
22         sum += temp;
23     }
24     printf("%d\n",sum);
25     fclose(stdin);
26     fclose(stdout);
27     return 0;
28 }
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 /**
 5     文件操作 
 6     练习:读取2组测试数据
 7     测试点1(in.txt):
 8     输入(in.txt):    5
 9                     2 3 5 7 6
10     输出(out.txt):    7
11     
12     测试点2(in2.txt):
13     输入(in2.txt):    6
14                     1 7 8 9 101 100
15     输出(out2.txt):101     
16 */
17 int main(){
18     FILE *fin,*fout;//实例化 
19     fin = fopen("in.txt","rb");
20     fout = fopen("out.txt","wb");
21     int temp,sum = 0;
22     while(fscanf(fin,"%d",&temp) == 1){
23         sum += temp;
24     }
25     fprintf(fout,"%d\n",sum);
26     fclose(fin);
27     fclose(fout);
28     return 0;
29 }
 1 #include <fstream>
 2 #include <cstdio>
 3 using namespace std;
 4 /**
 5     文件输入 
 6     由define标记的为常量 
 7 */ 
 8 #define fin cin 
 9 #define fout cout
10 int main(){
11     ifstream fin("in.txt");
12     ofstream fout("out.txt");
13     int temp,sum = 0;
14     while(cin >> temp){
15         sum += temp;
16     }    
17     cout << sum << endl;
18     fin.close();
19     fout.close(); 
20     return 0;
21 }
 1 #include <fstream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 /**
 6     文件输入 
 7     由define标记的为常量 
 8 */ 
 9 ifstream cin("in.txt");
10 ofstream cout("out.txt");
11 int main(){
12     int n;
13     cin >> n;
14     int a[n];
15     memset(a,0,sizeof(a));
16     for(int i = 0;i < n;i++){
17         cin >> a[i]; 
18     } 
19     for(int i = 0;i < n;i++){
20         cout << a[i] << "*"; 
21     } 
22     return 0;
23 }
 1 #include <fstream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 /**
 7     求最大值 
 8     练习:读取2组测试数据
 9     测试点1(in.txt):
10     输入(in.txt):    5
11                     2 3 5 7 6
12     输出(out.txt):    7
13     
14     测试点2(in2.txt):
15     输入(in2.txt):    6
16                     1 7 8 9 101 100
17     输出(out2.txt):101     
18 */ 
19 ifstream cin("in.txt");
20 ofstream cout("out.txt");
21 int main(){
22     int n;
23     cin >> n;
24     int a[n];
25     memset(a,0,sizeof(a));
26     for(int i = 0;i < n;i++){
27         cin >> a[i]; 
28     }
29     sort(a,a+n);
30     cout << a[n - 1]; 
31     return 0;
32 }
 1 #include <fstream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 /**
 7     结构体 
 8     struct 
 9 */
10 struct ahadadjakdjadaad{
11     string name;
12     int age;
13     double saraly;
14 }s[11];
15 int main(){
16     //实例化-不存在变成存在赋值的过程 
17     s.name s.age s.saraly//调用结构体的属性 
18     
19     return 0;
20 }
 1 #include <fstream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 /**
 7     成绩统计 
 8     4
 9     gaoxiang 78 96
10     wangxi 70 99
11     liujia 90 87
12     zhangjin 78 91
13 */
14 ifstream cin("cjtj.txt");
15 ofstream cout("out.txt");
16 struct cjtj{//结构体 
17     string name;
18     int chinese;
19     int math;
20     int sum;
21 }c[101];
22 bool comp(cjtj a1,cjtj a2){//排序规则 
23     if(a1.sum > a2.sum){
24         return true;
25     }
26     return false;
27 }
28 int main(){
29     int n;
30     //输入 
31     cin >> n;
32     for(int i = 0;i < n;i++){
33         cin >> c[i].name >> c[i].chinese >> c[i].math;
34         c[i].sum += c[i].chinese + c[i].math;
35     }
36     //算法 
37     sort(c,c + n,comp);
38     //输出 
39     for(int i = 0;i < n;i++){
40         cout << c[i].name << " " << c[i].chinese << " " << c[i].math << " " << c[i].sum << endl;
41     }
42     return 0;
43 } 
 1 #include <fstream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 /**
 7     成绩统计 
 8     4
 9     gaoxiang 78 96
10     wangxi 70 99
11     liujia 90 87
12     zhangjin 78 91
13 */
14 ifstream cin("cjtj.txt");
15 ofstream cout("out.txt");
16 struct cjtj{//结构体 
17     string name;
18     int chinese;
19     int math;
20     int sum;
21 }c[101];
22 bool comp(cjtj a1,cjtj a2){//排序规则 
23     if(a1.sum > a2.sum){
24         return true;
25     }
26     return false;
27 }
28 int main(){
29     int n;
30     //输入 
31     cin >> n;
32     for(int i = 0;i < n;i++){
33         cin >> c[i].name >> c[i].chinese >> c[i].math;
34         c[i].sum += c[i].chinese + c[i].math;
35     }
36     //算法 
37     sort(c,c + n,comp);
38     //输出 
39     for(int i = 0;i < n;i++){
40         cout << c[i].name << " " << c[i].chinese << " " << c[i].math << " " << c[i].sum << endl;
41     }
42     return 0;
43 } 
 1 #include <fstream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 /**
 7 甲流病人统计 
 8 */
 9 ifstream cin("jlin.txt");
10 ofstream cout("jlout.txt");
11 struct bingren{
12     string name;//姓名 
13     double tem;//体温 
14     bool cough;//是否咳嗽 
15 }b[201];
16 int main(){
17     int n,c = 0;
18     cin >> n;
19     //输入 
20     for(int i = 0;i < n;i++){
21         cin >> b[i].name >> b[i].tem >> b[i].cough;
22     }
23     //算法 
24     for(int i = 0;i < n;i++){
25         if(b[i].tem >= 37.5 && b[i].cough == 1){
26             c++;
27             //输出 
28             cout << b[i].name << endl;
29         } 
30     } 
31     cout << c << endl;
32     cin.close();
33     cout.close();
34     return 0;
35 }

 

posted @ 2019-07-25 18:01  灰灰老师  阅读(141)  评论(0)    收藏  举报