102
#include<iostream>
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
输出:_________
103
#include<iostream>
#include<string>
int main() {
string s;
char m1,m2;
int i;
getline(cin,s);
m1=m2='';
for (i=0;i<s.length();i++)
if (s[i]>m1) m2=m1,m1=s[i];
else if (s[i]>m2) m2=s[i];
cout<<int(m1)<<' '<<int(m2);
return 0;
}
输入:Expo 2010 Shanghai China
输出:_________
092
#include<iostream>
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
输出:_________
093
#include<iostream>
using namespace std;
const int c=2009;
int main() {
int n,p,s,i,j,t;
cin>>n>>p;
s=0;t=1;
for (i=1;i<=n;i++) {
t=t*p%c;
for (j=1;j<=i;j++) s=(s+t)%c;
}
cout<<s<<endl;
return 0;
}
输入:11 2
输出:_________
094
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=50;
void getnext(char str[]) {
int l=strlen(str),i,j,k;
k=l-2;
while (k>=0 && str[k]>str[k+1]) k--;
i=k+1;
while (i<l && str[i]>str[k]) i++;
swap(str[k],str[i-1]);
for (i=l-1;i>k;i--)
for (j=k+1;j<i;j++)
if (str[j]>str[j+1]) swap(str[j],str[j+1]);
return;
}
int main() {
char a[maxn];
int n;
cin>>a>>n;
while (n>0) {
getnext(a);
n--;
}
cout<<a<<endl;
return 0;
}
输入:NOIP 3
输出:_________
104
#include<iostream>
using namespace std;
const int NUM=5;
int r(int n) {
int i;
if (n<=NUM) return n;
for (i=1;i<=NUM;i++)
if (r(n-i)<0) return i;
return -1;
}
int main() {
int n;
cin>>n;
cout<<r(n);
}
1、输入:7
1、输出:_________
2、输入:16
2、输出:_________
114
#include<iostream>
using namespace std;
int solve(int n,int m) {
int i,sum;
if (m==1) return 1;
sum=0;
for(i=1;i<n;i++)
sum+=solve(i,m-1);
return sum;
}
int main() {
int n,m;
cin>>n>>m;
cout<<solve(n,m)<<endl;
return 0;
}
输入:7 4
输出:_________
123
#include<iostream>
using namespace std;
int n,i,j,a[100][100];
int solve(int x,int y) {
int u,v;
if (x==n) return a[x][y];
u=solve(x+1,y);
v=solve(x+1,y+1);
if (u>v) return a[x][y]+u;
else return a[x][y]+v;
}
int main() {
cin>>n;
for (i=1;i<=n;i++)
for (j=1;j<=i;j++)
cin>>a[i][j];
cout<<solve(1,1)<<endl;
return 0;
}
输入:
5
2
-1 4
2 -1 -2
-1 6 4 0
3 2 -1 5 8
输出:_________
124
#include<iostream>
#include<string>
using namespace std;
int n,ans,i,j;
string s;
char get(int i) {
if (i<n) return s[i];
else return s[i-n];
}
int main() {
cin>>s;
n=s.size();
ans=0;
for (i=1;i<=n-1;i++) {
for (j=0;j<=n-1;j++)
if (get(i+j)<get(ans+j)) {
ans=i;
break;
}else
if (get(i+j)>get(ans+j)) break;
}
for (j=0;j<=n-1;j++)
cout<<get(ans+j);
cout<<endl;
}
输入:CBBADADA
输出:_________
答案
102 99 101 111
103 120 112
092 416
093 782
094 NPOI (noipsh 3/nophis或者NOIP 4/OINP)
104 1、1 2、4
114 20
123 14
124 ACBBADAD