杭电2019
#include <iostream> #include <cstdlib> #include <iomanip> #include <climits> #include <stdio.h> #include <string.h> #include <list> using namespace std; int main() { list<int> a; int n,m,t; while(cin >> n >> m && (n!=0||m!=0)) { a.clear(); while(n--) { cin>>t; a.push_back(t); } a.push_back(m); a.sort(); for(list<int>::iterator it = a.begin();it!=a.end();++it) { cout << *it; advance(it,1); if (it!=a.end()) cout << ' '; else cout << endl; advance(it,-1); } } return 0; }
用了STL,很方便啊。。完全不用动脑子。。前18道题做的时候没保存,都没了。
2020
#include <iostream> #include <cstdlib> #include <cmath> #include <iomanip> #include <climits> #include <stdio.h> #include <string.h> using namespace std; int main() { int n,a[105]; while(cin>>n&&n) { int i = 0; while(i<n) cin >> a[i++]; for(int j=n-1; j>0; --j) for(int k=0; k<j; ++k) { if (abs(a[k]) < abs(a[k+1])){ swap(a[k],a[k+1]); } } i = 0; while(i<n-1) cout << a[i++] << ' '; cout << a[n-1] << endl; } return 0; }
2021
#include <iostream> #include <cstdlib> #include <cmath> #include <iomanip> #include <climits> #include <stdio.h> #include <string.h> using namespace std; int main() { int n,sum,money,a[6]={100,50,10,5,2,1}; while(cin>>n&&n) { sum = 0; while(n--) { cin >> money; for(int i = 0; i<6; ++i) { sum += money/a[i]; money %= a[i]; } } cout << sum << endl; } return 0; }
2022
#include <iostream> #include <cmath> #include <stdio.h> #include <stdlib.h> #include <string.h> using namespace std; int main() { int n,m,x,y,s; int a[100][100]; while(cin>>n>>m) { x=0; y=0; for(int i=0;i<n;++i) for(int j=0;j<m;++j) { cin >> a[i][j]; } for(int i=0;i<n;++i) for(int j=0;j<m;++j) { if(abs(a[x][y])<abs(a[i][j])){ x=i; y=j; s=a[i][j]; } } cout << x+1 << ' ' << y+1 << ' ' << s << endl; } return 0; }
2023
#include <iostream> #include <cmath> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iomanip> using namespace std; int main() { int n,m,a[50][5],sum,flag; double classaverage[5],studentaverage[50]; while(cin >> n >> m) { memset(classaverage,0,sizeof(classaverage)); memset(studentaverage,0,sizeof(studentaverage)); sum = 0; for(int i=0;i<n;++i) for(int j=0;j<m;++j){ cin >> a[i][j]; classaverage[j] += a[i][j]; studentaverage[i] += a[i][j]; } for(int i=0;i<n-1;++i) cout << fixed << setprecision(2) <<studentaverage[i]/m << ' '; cout << fixed << setprecision(2) << studentaverage[n-1]/m << endl; for(int i=0;i<m-1;++i) cout << fixed << setprecision(2) << classaverage[i]/n << ' '; cout << fixed << setprecision(2) << classaverage[m-1]/n << endl; for(int i=0;i<n;++i){ flag=1; for(int j=0;j<m;++j) if(a[i][j] < (classaverage[j]/n)) flag = 0; if(flag) sum++; } cout << sum << endl << endl; } return 0; }
2024
#include <iostream> #include <cmath> #include <stdio.h> #include <stdlib.h> #include <cstring> #include <iomanip> using namespace std; int main() { int n,flag; char a[50]; while(cin >> n) { memset(a,0,50); getchar(); while(n--) { flag=1; gets(a); int i = strlen(a); while(i--) if(!((a[i]>='a' && a[i]<='z')||(a[i]>='A' && a[i]<='Z')|| a[i]=='_' || (a[i]>='0' && a[i]<='9'))) flag =0; if(!((a[0]>='a' && a[0]<='z')||(a[0]>='A' && a[0]<='Z')|| a[0]=='_')) flag = 0; puts(flag?"yes":"no"); } } return 0; }