读程序写结果 选拔培训

阅读: 评论:0

读程序写结果 选拔培训

读程序写结果 选拔培训

一、看程序写结果:

1、NOIP 2013 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int a, b;cin >> a >> b;cout << a << "+" << b << "=" << a + b << endl;
}

输入: 3 5

输出:               

 

2、NOIP 2012 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,ans;
int main()
{	cin>>a>>b>>c;d=a+b;e=b+c;ans=d+e;cout<<ans<<endl;return 0;	
}

输入:1 2 5

输出:               

 

3、NOIP 2014 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int a, b, c, d, ans;cin >> a >> b >> c;d = a - b;a = d + c;ans	= a * b;cout << "Ans = " << ans << endl; return(0);
}

输入:2 3 4
输出:Ans =                        

 

#include<bits/stdc++.h>
using namespace std;
int main()
{  int x,y,z1,z2;x=7;   y=8;z1=y-(x++); z2=y-(++x);   cout<<"z1="<<z1<<endl<<"z2="<<z2; 
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int i=0, j=0, a=6;if ((++i>0)&&(++j>0)) a++;printf ("i=%d, j=%d, a=%dn", i,j,a);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  int  i=0, j=0, k=6;if ((++i>0)||(++j>0)) k++;printf("%d, %d, %dn", i, j, k);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int m=5;if(m++>5) printf("%dn",m);else printf("%dn",m--);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{char c1,c2,c3;c1 = 48;c2 = 65;c3 = 97;cout << c1 << “ “ << c2 << “ “ << c3 << “ “ ;cout << int(c1) << “ “ << int(c2) << “ “ << int(c3) << endl;return 0;
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int i=111;if(i%3==0)  printf("####");else printf("****");
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int x, y;scanf("%d", &x);y=x>12 ? x+10:x-12;printf("%dn", y);
}

输入:12

输出:               

4、NOIP 2015 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main() 
{   int a, b, c; a = 1;b = 2;c = 3;if(a > b)if(a > c)  cout << a << ' ';else       cout << b << ' '; cout << c << endl;return 0;
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  int a=1,b=3,c=5,d=4,x;if(a<b)if(c<d) x=1;elseif(a<c)if(b<d) x=2;else x=3;else x=6;else x=7;cout<<x;
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{ int a=2,b=-1,c=2;if(a<b)if(b<0) c=0;else c++;printf("%dn",c);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  int a=1,b=2,c=3;if(a>b)a=b;b=c;c=a;printf("a=%d b=%d c=%dn",a,b,c);
}

输出:               

#include<bits/stdc++.h>
using namespace std;
int main()
{  char i;for (; (i=getchar ())!='n';){switch (i-'a'){case 0: putchar (i);case 1: putchar (i+1);break;case 2: putchar (i+2);  case 3: break;default:  putchar (i);break;}}printf ("n");
}

输出:               

5、NOIP 2011 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{   int i,n,m,ans;cin>>n>>m;i=n;ans=0;while(i<=m){  ans+=i;i++;}cout<<ans<<endl;return 0;
}

输入:10 20

输出:               

 

6、NOIP 2008 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int i, a, b, c, d, f[4];for(i = 0; i < 4; i++) cin >> f[i];a = f[0] + f[1] + f[2] + f[3];a = a / f[0];b = f[0] + f[2] + f[3];b = b / a;c = (b * f[1] + a) / f[2];d = f[(b / c ) % 4];if(f[(a + b + c + d) % 4] > f[2])cout << a + b<< endl;else cout << c + d << endl;return 0;
}

输入:9 19 29 39

输出:               

 

7、NOIP 2007 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{int i, p[5], a, b, c, x, y = 20;for ( i = 0; i <= 4; i++ )scanf( "%d", &p[i] );a = (p[0] + p[1]) + (p[2] + p[3] + p[4]) / 7;b = p[0] + p[1] / ( (p[2] + p[3]) / p[4]);c = p[0] * p[1] / p[2];x = a + b - p[(p[3] + 3) % 4];if ( x > 10 )y += (b * 100 - a) / (p[p[4] % 3] * 5);elsey += 20 + (b * 100 - c) / (p[p[4] % 3] * 5);printf( "%d,%dn", x, y );return(0);
}

{注:本例中,给定的输入数据可以避免分母为0或数组元素下表越界。} 输入:6 6 5 5 3

输出:               

 

8、NOIP 2010 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
void swap(int & a, int & b)
{   int t;t = a;a = b;b = t;
}
int main()
{   int a1, a2, a3, x;        cin>>a1>>a2>>a3;if (a1 > a2)    swap(a1, a2);if (a2 > a3)    swap(a2, a3);if (a1 > a2)    swap(a1, a2);    cin>>x;if (x < a2)if (x < a1) cout<<x<<' '<<a1<<' '<<a2<<' '<<a3<<endl;else        cout<<a1<<' '<<x<<' '<<a2<<' '<<a3<<endl;elseif (x < a3)   cout<<a1<<' '<<a2<<' '<<x<<' '<<a3<<endl;else          cout<<a1<<' '<<a2<<' '<<a3<<' '<<x<<endl;    return 0;
}

输入:
91 2 20
77

输出:               

 

10、NOIP 2016 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{   int max, min, sum, count = 0;int tmp;cin >> tmp;if (tmp == 0)  return 0;max = min = sum = tmp;count++;while (tmp != 0){   cin >> tmp;if (tmp != 0){   sum += tmp;count++;if (tmp > max)    max = tmp;if (tmp < min)    min = tmp;}}cout << max << "," << min << "," << sum / count << endl;return 0;
}

输入: 1 2 3 4 5 6 0 7

输出: _________

 

11、NOIP 2018 普及组初赛18题

#include<bits/stdc++.h>
using namespace std;
char st[100];
int main()
{	scanf("%s", st);for (int i = 0; st[i]; ++i)if ('A' <= st[i] && st[i] <= 'Z')	st[i] += 1;	printf("%sn", st);return 0;
}

输入:QuanGuoLianSai

输出:_________

 

11、NOIP 2017 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int main()
{   int t[256];string s;int i;cin >> s;for (i = 0; i < 256; i++)          t[i] = 0;for (i = 0; i < s.length(); i++)   t[s[i]]++;for (i = 0; i < s.length(); i++)if (t[s[i]] == 1){   cout << s[i] << endl;return 0;}cout << "no" << endl;return 0;
}

输入:xyzxyw
输出:_________

 

13、NOIP 2019 普及组初赛16题

#include<bits/stdc++.h>
using namespace std;
char st[100];
int main()
{   scanf("%s", st);int n = strlen(st);for (int i = 1; i <= n; ++i) if (n % i == 0) {   char c = st[i - 1];if (c >= 'a')   st[i - 1] = c - 'a' + 'A';}    printf("%s", st);return 0;
}

•判断题

1、输入的字符串只能由小写字母或大写字母组成。()
2、若将第8行的“i = 1”改为“i = 0”,程序运行时会发生错误。()
3、若将第8行的“i <= n”改为“i * i <= n”,程序运行结果不会改变。()
4、若输入的字符串全部由大写字母组成,那么输出的字符串就跟输入的字符串一样。()
•选择题
5、若输入的字符串长度为18,那么输入的字符串跟输出的字符串相比,至多有()个字符不同。

6、若输入的字符串长度为(),那么输入的字符串跟输出的字符串相比,至多有36个字符不同。

1、 A. 正确   B. 错误

2、 A. 正确   B. 错误

3、A. 正确   B. 错误

4、A. 正确   B. 错误

5、 A. 18       B. 6                 C. 10       D. 1

6、 A. 36       B. 100000       C. 1         D. 128

 

14、NOIP 2020 普及组初赛16题

#include<bits/stdc++.h>
using namespace std;
char encoder[26] = {'C','S','P',0};
char decoder[26];
string st;
int main()
{ int k = 0;for (int i = 0; i < 26; ++i)    if (encoder[i] != 0) ++k;for (char x ='A'; x <= 'Z'; ++x){ bool flag = true;for (int i = 0; i < 26; ++i)if (encoder[i] ==x) { flag = false;  break; }if (flag) {  encoder[k]= x;   ++k;  }}for (int i = 0; i < 26; ++i) decoder[encoder[i]- 'A'] = i + 'A';cin >> st;for (int i = 0; i < st.length( ); ++i)   st[i] = decoder[st[i] -'A'];cout << st;return 0;
}

判断题

1) 输入的字符串应当只由大写字母组成,否则在访问数组时可能越界。( )
2) 若输入的字符串不是空串,则输入的字符串与输出的字符串一定不一样。()
3) 将第 12 行的“i < 26”改为“i < 16”,程序运行结果不会改变。( )
4) 将第 26 行的"i < 26”改为“i < 16”,程序运行结果不会改变。( )

•单选题

5) 若输出的字符串为“ABCABCABCA”,则下列说法正确的是( )。

6)若输出的字符串为“CSPCSPCSPCSP”,则下列说法正确的是( )。

1. A. 正确   B. 错误

2. A. 正确   B. 错误

3. A. 正确   B. 错误

4 A. 正确   B. 错误

5. A. 输入的字符串中既有S又有P       B. 输入的字符串中既有S又有B      C. 输入的字符串中既有A又有P       D. 输入的字符串中既有A又有B

6. A. 输入的字符串中既有P又有K       B. 输入的字符串中既有J又有R      C. 输入的字符串中既有J又有K        D. 输入的字符串中既有P又有R

 

 

1、NOIP 2007 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
void fun( int *a, int *b )
{    int *k;k = a; a = b; b = k;
}
main()
{    int a = 3, b = 6, *x = &a, *y = &b;fun( x, y );printf( "%d,%d ", a, b );
}

输出:               

 

2、NOIP 2008 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
void foo(int a, int b, int c)
{	if(a > b) 	foo(c, a, b);else		cout<<a<<','<<b<<','<<c<<endl;
}
int main()
{	int a, b, c;cin >> a >> b >> c;foo(a, b, c);return 0;
}

输入: 3 1 2

输出:               

 

 

3、NOIP 2009 普及组初赛23题

#include<bits/stdc++.h>
using namespace std;
int a,b;
int work(int a,int b)
{	if (a%b) return work(b,a%b);return b;
}
int main()
{	cin >> a >> b;cout << work(a,b) << endl;return 0;
}

输入:20 12

输出:               

 

3、NOIP 2009 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int main()
{	int a[3],b[3];int i,j,tmp;for (i=0;i<3;i++)	cin >> b[i];for (i=0;i<3;i++){	a[i]=0;for (j=0;j<=i;j++){	a[i]+=b[j];b[a[i]%3]+=a[j];}}tmp=1;for (i=0;i<3;i++){	a[i]%=10;b[i]%=10;tmp*=a[i]+b[i];}cout << tmp << endl;return 0;
}

输入:2 3 5

输出:               

 

4、NOIP 2010 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int rSum(int j)
{   int sum = 0;while (j != 0){   sum = sum * 10 + (j % 10);j = j / 10;}return sum;
}
int main()
{   int n, m, i;        cin>>n>>m;for (i = n; i < m; i++)if (i == rSum(i))  cout<<i<<' ';return 0;
}

输入:90 120

输出:               

 

5、NOIP 2011 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int main()
{   string map= "2223334445556667778889999";string tel;int i;cin>>tel;for(i=0;i<tel.length();i++)if((tel[i]>='0') && (tel[i]<='9') )          cout<<tel[i];else if( (tel[i]>='A') && (tel[i]<='Z'))     cout<<map[tel[i]-'A'];cout<<endl;return 0;
}

输入:CCF-NOIP-2011

输出:               

 

6、NOIP 2012 普及组初赛24题

#include<bits/stdc++.h>
using namespace std;
int n,i,ans;
int main()
{	cin>>n;ans=0;for(i=1;i<=n;i++)	if(n%i==0) ans++;cout<<ans<<endl;return 0;	
}

输入:18

输出:               

 

7、NOIP 2013 普及组初赛24题

 

输出:               

 

8、NOIP 2014 普及组初赛24题

 

输出:               

 

9、NOIP 2015 普及组初赛24题

 

输出:               

 

10、NOIP 2016 普及组初赛24题

 

输出:               

11、NOIP 2017 普及组初赛24题

 

输出:               

 

12、NOIP 2018 普及组初赛24题

 

输出:               ​​​​​​​

13、NOIP 2019 普及组初赛17题

 

输出:               ​​​​​​​

14、NOIP 2020 普及组初赛17题

 

输出:               ​​​​​​​

1、NOIP 2007 普及组初赛25题

#include<bits/stdc++.h>
using namespace std;
main()
{	int a1[51] = { 0 };int i, j, t, t2, n = 50;for ( i = 2; i <= sqrt( n ); i++ )if ( a1[i] == 0 ){	t2 = n / i;for ( j = 2; j <= t2; j++ ) a1[i * j] = 1;}t = 0;for ( i = 2; i <= n; i++ )if ( a1[i] == 0 ){	printf( "%4d", i ); t++;if ( t % 10 == 0 )	printf( "n" );}printf( "n" );
}

输出:               

 

1、NOIP 2007 普及组初赛26题

#include<bits/stdc++.h>
using namespace std;
void expand( char s1[], char s2[] )
{	int i, j, a, b, c;j = 0;for ( i = 0; (c = s1[i]) != ''; i++ )if ( c == '-' ){	a = s1[i - 1]; b = s1[i + 1];if ( isalpha( a ) && isalpha( b ) || isdigit( a ) && isdigit( b ) )
/*函数isalpha(a)用于判断字符a是否为字母,isdigit(b) 用于判断字符b是否为数字,如果是,返回1,否则返回0 */{   j--;do	s2[j++] = a++;while ( tolower( a ) < tolower( s1[i + 1] ) );}
/*函数tolower(a)的功能是当字符a是大写字母,改为小写,其余情况不变*/else s2[j++] = c;}else s2[j++] = c;s2[j] = '';
}
main()
{	char s1[100], s2[300];printf( "input s1:" );gets( s1 );expand( s1, s2 );printf( "%sn", s2 );
}

输入:wer2345d-h454-82qqq

输出:               


 


 

1、NOIP 2008 普及组初赛25题

#include<bits/stdc++.h>
using namespace std;
void func(int ary[], int n )
{	int i=0, j, x;j=n-1;while(i<j){	while (i<j&&ary[i]>0) i++;while (i<j&&ary[j]<0) j--;if (i<j){	x=ary[i];ary[i++]=ary[j];ary[j--]=x;}}
}
int main()
{	int a[20], i, m;m=10;for(i=0; i<m; i++)	cin>>a[i];func(a, m);for (i=0; i<m; i++)		cout<<a[i]<<" ";cout<< endl;return 0;
}

输入:5 4 -6 -11 6 -59 22 -6 1 10

输出:               

 

1、NOIP 2008 普及组初赛26题

#include<bits/stdc++.h>
using namespace std;
#define MAX 100
void solve(char first[], int spos_f, int epos_f, char mid[], int spos_m, int epos_m)
{	int i, root_m;if(spos_f > epos_f)		return;for(i = spos_m; i <= epos_m; i++)if(first[spos_f] == mid[i]){	root_m = i;break;}solve(first, spos_f + 1, spos_f + (root_m - spos_m), mid, spos_m, root_m - 1);solve(first, spos_f + (root_m - spos_m) + 1, epos_f, mid, root_m + 1, epos_m);cout << first[spos_f];
}
int main()
{	char first[MAX], mid[MAX];int len;cin >> len;cin >> first >> mid;solve(first, 0, len - 1, mid , 0, len - 1);	cout << endl;return 0;
}

输入:
7
ABDCEGF
BDAGECF

输出:               

 

 

 

 

二、完形填空:

1、NOIP 2007 普及组初赛27题

#include<bits/stdc++.h>
using namespace std;
int maxline = 200, kz;
int reverse( char s[] )
{	int i, j, t;for ( i = 0, j = strlen( s ) - 1; i < j; 【①】 , 【②】 )t = s[i]; s[i] = s[j]; s[j] = t;return(0);
}
int main()
{	char line[100];cout << "continue? -1 for end." <<endl;cin>>kz;while(【③】){   cin  >>  line;【④】;cout << line  <<  endl;cout << "continue ? -1 for end." << endl;cin >> kz;}
}

输出:

1、                                      

2、                                      

3、                                      

4、                                      

 

1、NOIP 2007 普及组初赛28题
(棋盘覆盖问题)在一个2^ktimes 2^k2k×2k个方格组成的棋盘中恰有一个方格与其它方格不同(图中标记为-1的方格),称之为特殊方格。现用L型(占3个小方格)纸片覆盖棋盘上除特殊方格的所有部分,各纸片不得重叠,于是,用到的纸片数恰好是(4^k-1)/3(4k−1)/3。在下表给出的一个覆盖方案中,k=2,相同的3各数字构成一个纸片。下面给出的程序使用分治法设计的,将棋盘一分为四,依次处理左上角、右上角、左下角、右下角,递归进行。请将程序补充完整。

#include<bits/stdc++.h>
using namespace std;
int board[65][65], tile; /* tile为纸片编号 */
void chessboard( int tr, int tc, int dr, int dc, int size )/* dr,dc依次为特殊方格的行、列号 */
{	int t, s;if ( size == 1 )   ⑤ ;t = tile++;s = size / 2;if ( ⑥ ) chessboard( tr, tc, dr, dc, s );else{	board[tr + s -1][tc + s -1] = t;[⑦];}if ( dr < tr + s && dc >= tc + s )	chessboard( tr, tc + s, dr, dc, s );else{	board[tr + s -1][tc + s] = t;⑧;}if ( dr >= tr + s && dc < tc + s )	chessboard( tr + s, tc, dr, dc, s );else{	board[tr + s][tc + s -1] = t;[⑨];}if ( dr >= tr + s && dc >= tc + s )	chessboard( tr + s, tc + s, dr, dc, s );else{   board[tr + s][tc + s] = t;[⑩]; }
}
void prtl( int b[][65], int n )
{	int i, j;for ( i =1; i <= n; i++ ){	for ( j =1; j <= n; j++ ) cout << setw( 3 ) << b[i][j];cout << endl;}
}
int main()
{	int size, dr, dc;cout << "input size(4/8/16/64):" << endl;cin >> size;cout << "input the position of special block(x,y):" << endl;cin >> dr >> dc;board[dr][dc] = -1;tile++;chessboard( 1, 1, dr, dc, size );prtl( board, size );
}

输出:

1、                                      

2、                                      

3、                                      

4、                                      

5、                                      

6、                                      

 

1、NOIP 2008 普及组初赛27题

(字符串替换)给定一个字符串S(S仅包含大小写字母),下面的程序将S中的每个字母用规定的字母替换,并输出S经过替换后的结果。程序的输入是两个字符串,第一个字符串是给定的字符串S,第二个字符串S’由26个字母组成,它是a-z的任一排列,大小写不定,S’规定了每个字母对应的替换字母:S’中的第一个字母是字母A和a的替换字母,即S中的A用该字母的大写替换,S中的a用该字母的小写替换;S’中的第二个字母是字母B和b的替换字母,即S中的B用该字母的大写替换,S中的b用该字母的小写替换;…… 以此类推。

#include<bits/stdc++.h>
using namespace std;
char change[26], str[5000];
void CheckChangeRule()
{   int i;for (i = 0;i < 26;i ++)if ( [    ①     ] )  change[i] -= 'A' - 'a';   
}
void ChangeString()
{   int i;for (i = 0;i <strlen(str);i ++){   if (  [   ②   ]  )      str[i] = change[str[i] - 'A'] -'a' + 'A';else  [         ③        ]          }
}
int main()
{	int i;cin >> str ;cin >> change;CheckChangeRule();[              ④            ] cout << str << endl;return 0;
}

输出:

1、                                      

2、                                      

3、                                      

4、                                      

 

 

 

 

 

本文发布于:2024-01-29 01:13:28,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170646201111653.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:程序
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23