CCF计算机职业资格认证考试资料
数据范围
附:试题案例
问题描述
输入A,B。
输出A+B。
输入格式
输入包含两个整数A,B,用一个空格分隔。
输出格式
输出一个整数,表示A+B的值。
样例输入
1 2
样例输出
3
数据规模和约定
-1,000,000,000<=A,B<=1,000,000,000。
解决此题的一个C++程序示例:
//example.cpp#include<iostream>using namespace std;int main(){int a, b;cin >> a >> b;cout << a + b;return 0;}
问题描述
//03-1.cpp#include<iostream>using namespace std;int main(){int m,n;cin>>m>>n;int s[m+1][n+1],i,j;for(i=1;i<=m;i++){for(j=1;j<=n;j++)cin>>s[i][j];}for(i=n;i>0;i--){for(j=1;j<=m;j++)cout<<s[j][i]<<" ";cout<<endl;}return 0;}
问题描述
//03-2.cpp#include<iostream>using namespace std;int main(){int n,t,i,j,max,s[1001],k[1001];cin>>n;for(i=1;i<1001;i++)s[i]=0;for(i=0;i<n;i++){cin>>t;s[t]++;if(t>max)max=t;}for(i=1;i<=max;i++){k[i]=i; }for(i=1;i<max;i++){for(j=i+1;j<=max;j++){if(s[k[j]]>s[k[i]]){t=k[j];k[j]=k[i];k[i]=t; }if(s[k[j]]==s[k[i]]&&k[j]<k[i]){t=k[j];k[j]=k[i];k[i]=t; } }}for(i=1;i<=max;i++){if(s[k[i]]!=0)cout<<k[i]<<""<<s[k[i]]<<endl;}return 0;}
问题描述
//03-3.cpp#include<iostream>#include <cstdio>//printf库#include<algorithm>//max,min库using namespace std;intday[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};/* 1 2 3 4 5 6 7 8 9 1011 12 */bool isRunNian(int y){if(y%400==0)return true;if(y%4==0 && y%100!=0)return true;return false;}int main(){int a,b,c,d,e,y1,y2,i,j,k;cin>>a>>b>>c>>d>>e;y1=min(d,e);y2=max(d,e);d=1;for(i=1850;i<y1;i++){if(isRunNian(i))d+=366;elsed+=365;}c%=7;d%=7;for(i=y1;i<=y2;i++){for(j=1;j<=12;j++){if(j==a){k=(b-1)*7+1;while((d+k)%7!=c){k++;}if(k>day[isRunNian(i)][j])cout<<"none"<<endl;elseprintf("%d/%02d/%02d\n",i,j,k);}d+=day[isRunNian(i)][j];d%=7;}}return 0;}
问题描述
//12-1.cpp#include<iostream>using namespace std;int main(){int n,i,j;cin>>n;int s[n+1];for(i=1;i<=n;i++){cin>>s[i];}for(i=1;i<=n;i++){s[0]=0;for(j=i;j>0;j--)if(s[j]==s[i])s[0]++;cout<<s[0]<<" ";}cout<<endl;return 0;}
问题描述
//12-2.cpp#include<iostream>using namespace std;int main(){int n,i,j,k;cin>>n;int s[n+1][n+1];for(i=1;i<=n;i++){for(j=1;j<=n;j++){cin>>s[i][j];}}i=1;j=1;bool flg=true;for(k=2;k<=2*n;k++){if(flg){while(i && j<=n){cout<<s[i][j]<<" ";j++;i=k-j;}flg=false;if(j>n){j--;i+=2;}else{i=1;}}else{while(j && i<=n){cout<<s[i][j]<<" ";i++;j=k-i;}flg=true;if(i>n){i--;j+=2;}else{j=1;}}}return 0;}
问题描述
//09-1.cpp#include<iostream>using namespace std;int main(){intn,i,j,temp;cin>>n;ints[n+1];i=n;while(i){cin>>s[i];i--;}for(i=1;i<n;i++){for(j=i+1;j<=n;j++){if(s[j]<s[i]){temp=s[j];s[j]=s[i];s[i]=temp;} }//cout<<s[i]<<endl;}temp=0;for(i=1;i<n;i++){if(s[i+1]-s[i]==1)temp++;}cout<<temp;return 0;}
问题描述
//09-2.cpp#include<iostream>#include <algorithm>using namespace std;int main(){intn,i,j,k,minX=100,maxX=0,minY=100,maxY=0;cin>>n;ints[4][n+1];i=n;while(i){cin>>s[0][i]>>s[1][i]>>s[2][i]>>s[3][i];minX=min(minX,s[0][i]);minY=min(minY,s[1][i]);maxX=max(maxX,s[2][i]);maxY=max(maxY,s[3][i]);i--;}//cout<<minX<<""<<maxX<<endl<<minY<<""<<maxY<<endl;s[0][0]=0;boolflg;for(i=minX+1;i<=maxX;i++){for(j=minY+1;j<=maxY;j++){flg=false;for(k=1;k<=n;k++){if(i>s[0][k]&& i<=s[2][k] && j>s[1][k] && j<=s[3][k])flg=true;}if(flg)s[0][0]++; }}cout<<s[0][0];return0;}
问题描述
//12-1.cpp#include<iostream> using namespace std;int main(){intn,i,j,temp;cin>>n;ints[n+1],t[n];i=n;while(i){cin>>s[i];i--;}for(i=1;i<n;i++){for(j=i+1;j<=n;j++){if(s[j]<s[i]){temp=s[j];s[j]=s[i];s[i]=temp;} }}for(i=1;i<n;i++){j=1;while(s[i+j]==s[i]&&i+j<=n){j++; }t[i]=j;}temp=1;for(i=1;i<n;i++){if(t[i]>t[temp])temp=i;}cout<<s[temp];return 0;}
问题描述
//12-2.cpp#include<iostream>using namespace std;int main(){char s[14],k;cin >> s;k=(s[0]*1+s[2]*2+s[3]*3+s[4]*4+s[6]*5+s[7]*6+s[8]*7+s[9]*8+s[10]*9-2160)%11+48;if(k==s[12] || (s[12]-k)==30 )cout<<"Right";else{if(k==58)k=88;s[12]=k;cout<<s;}return 0;}
问题描述
//12-3.cpp#include<iostream>using namespace std;int main(){intn,i,j,k,max=0,min;cin>>n;ints[n+1],t[n+1];i=n;while(i){cin>>s[i];i--;}max=0;for(k=1;k<=n;k++){for(i=1;i<=n+1-k;i++){t[i]=0;min=s[i];for(j=1;j<=k;j++){if(s[i-1+j]<min)min=s[i-1+j];}if(max<k*min)max=k*min; }}cout<<max;return0;}
问题描述
//03-1.cpp#include<iostream>using namespace std;int main(){intn,i,j,count=0;cin>>n;ints[n+1];i=n;while(i){cin>>s[i];i--;}for(i=1;i<n;i++){for(j=i+1;j<=n;j++){if((s[i]+s[j])==0)count++;}}cout<<count<<endl;return0;}