#include<bits/stdc++.h>
using namespace std;
int main()
{
int x, y;
while (cin>>x>>y) {
cout<<x<<"*"<<y<<"=";
int sum = x * y;
int a[100];
int i = 0;
while (x != 1 ) {
if (x % 2 != 0) {
a[i++] = y;
}
x /= 2;
y *= 2;
}
a[i] = y;
for (int j = 0; j <= i; j++) {
cout<<a[j];
if (j != i) {
cout<<"+";
}
}cout<<"="<<sum<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while (cin>>n) {
int a[200] = {0};
int i, sum = 0;
for (i = 1;;i++) {
a[i] = i;
sum += i;
if (sum + i + 1 > n) {
break;
}
}
int surplus = n - sum;
for (int j = i; surplus--; j--) {
a[j]++;
}
for (int k = 1; k <= i; k++) {
cout<<a[k];
if (k == i) {
cout<<endl;
} else {
cout<<",";
}
}
}
return 0;
}
我的代码,运行正确,ojWA 正确输出 127 129 130 135 141 142 150 151 154 160 164 170 错误输出: 126 130 131 136 142 151 155 161 165 171 179 186
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
using namespace std;
int hw(int s)
{
int ans=0;
for(int i=2;i<=10;i++)
{
if(ans==2) break;
int s0=s,j=0;
long long x=0;
while(s0)
{
x+=(s0%i)*pow(10,j);
s0/=i;
j++;
}
stringstream t;
string s;
t<<x;
t>>s;
int ls=s.size(),l=0;
while(s[l]==s[ls-1-l] && l<=(ls-1)/2)
{
l++;
}
l--;
if(l==(ls-1)/2) ans++;
}
return ans;
}
int main(){
int n,s,num=0;
cin>>n>>s;
while(num<n)
{
s++;
if(hw(s)==2)
{
cout<<s<<endl;
num++;
}
}
return 0;
}
AC的
#include <bits/stdc++.h>
using namespace std;
int sum;
int a[100];
int k;
int basecnt;
int jin;
void change(int n){
basecnt=0;
while(n!=0){
a[basecnt]=n%jin;
n/=jin;
basecnt++;
}
return ;
}
int main(){
int n;
cin>>sum>>n;
int tmp;
bool tf=false;
int cnt=0;
int cnt2=n+1;
while(cnt<sum){
int cnt3=0;
for(int i=2;i<=10;i++){
memset(a,0,sizeof(a));
jin=i;
change(cnt2);
tf=false;
for(int j=0;j<basecnt;j++){
if(a[j]!=a[basecnt-1-j]){
tf=true;
}
}
if(tf==false){
if(cnt3==1){
cout<<cnt2<<endl;
cnt++;
break;
}else{
cnt3++;
}
}
}
cnt2++;
}
return 0;
}
TLE
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
int maxn = 105;
int n,m,k;
cin>>k;
while (k != 0 && k--) {
while(scanf("%d%d",&n,&m)&&(n!=0||m!=0)){
int i,j,a[maxn],b[maxn];
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=0;i<m;i++) scanf("%d",&b[i]);
int c[maxn],t=0;
for(i=0;i<n;i++){
int x=0;
for(j=0;j<m;j++)
if(a[i]==b[j]) x++;
if(x==0) {c[t]=a[i];t++;}
}
if(t==0) {printf("NULL\n");}
int k;
for(i=1;i<t;i++)
for(j=0;j<t-i;j++)
if(c[j]>c[j+1]) { k=c[j];c[j]=c[j+1];c[j+1]=k;}
for(i=0;i<t;i++){
cout<<c[i]<<" ";
if(i==t-1) printf("\n");
}
}
}
return 0;
}
AC
#include <stdio.h>
int main() {
int T, n,m,i,a[105],b[105],k,j,count,temp;
scanf("%d",&T);
for(i=0;i<T;i++) {
count=0;
scanf("%d%d",&n,&m);
for(j=0;j<n;j++)
scanf("%d",&a[j]);
for(j=0;j<m;j++)
scanf("%d",&b[j]);
for(j=0;j<n;j++) {
for(k=1;k<n-j;k++) {
if(a[k-1]>a[k]) {
temp=a[k-1];
a[k-1]=a[k];
a[k]=temp;
}
}
}
for(j=0;j<n;j++) {
for(k=0;k<m;k++) {
if(a[j]==b[k])
break;
}
if(k==m) {
printf("%d ",a[j]);
count++;
}
}
if(count !=0)
printf("\n");
if(count==0)
printf("NULL\n");
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int fu(int height[],int N){
int point[100]={0};
int i,j;
int sum=0;
for(i=0;i<N;i++)
for(j=0;j<N;j++){
if(point[j]>height[i]){
point[j]=height[i];
break;
}
if(point[j]==0){
point[j]=height[i];
sum++;
break;
}
}
return sum;
}
int main(){
int T;
while(cin>>T){
while(T--){
int N;
cin>>N;
int i;
int a[N];
for(i=0;i<N;i++)
scanf("%d",&a[i]);
int sum=fu(a,N);
printf("%d\n",sum);
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
void f();
int main()
{
f();
return 0;
}
void f() {
int n;
while (scanf("%d", &n) != EOF)
{
int a[1001] = {0}, alen = 0;
a[0] = 1; alen = 1;
for (int k = 2; k <= n; k++)
{
int b[5], blen = 0, c[1001] = {0}, clen = 0;
int m = k;
int carry = 0;
while (m != 0)
{
b[blen++] = m % 10;
m /= 10;
}
for (int i = 0; i < blen; i++)
{
clen = 0;
clen += i;
for (int j = 0; j < alen; j++)
{
int num = c[clen] + carry + b[i] * a[j];
c[clen] = num % 10;
carry = num / 10;
clen++;
}
while (carry != 0)
{
c[clen++] = carry % 10;
carry /= 10;
}
}
memset(a, 0, sizeof(a));
for (int i =0; i<clen; i++)
{
a[i] = c[i];
}
alen = clen;
}
for (int i = alen - 1; i >= 0; i--)
{
printf("%d", a[i]);
}
printf("\n");
}
}
#include<bits/stdc++.h>
using namespace std;
int prime(int a) {
if (a < 2) return 0;
for (int i = 2; i < a; i++) {
if (a % i == 0) return 0;
}return 1;
}
int main()
{
int m, n;
while (cin>>m>>n) {
for(int j = 0;m<=n;m++)
{ if(prime(m)){
cout<<m<<" ";
j++;
if(j%10==0)
cout<<endl;
}
}
}return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
double sum;
while (cin>>n) {
sum = 0;
for(int i = 1;i <= n; i++) {
sum += 1.0/i;
}
cout<<fixed<<setprecision(3)<<sum<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int fact(int n) {
int j = 1;
for (int i = 1; i <= n; i++) {
j *= i;
}
return j;
}
int main()
{
int n, m, p;
double sum;
while (cin>>m>>n) {
p = fact(m)/fact(m-n);
cout<<p<<endl;
}
return 0;
}
|