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]) != '