大佬求助

P1001 A+B Problem

C1WXY @ 2024-09-11 14:00:14

这道题全WA,大佬能帮忙看看吗

#include<bits/stdc++.h>
using namespace std;
void js(int a,int b,int num)
{
    num=0;
    for(int i=1;i<=a;i++)
    {
        num++;
    }
    cout<<num+a-10;
}
int main()
{
    int a[2],z=0;
    bool s=0;
    int num=0;
    int i=0;
    while(s==0)
    {
        cin>>a[i];
        i++;
        z++;
        if(z==2)
            s++;
    }
    js(a[1],a[2],num);
    return 0;
}

by _chicken_ @ 2024-09-11 14:10:09

#include<bits/stdc++.h>
using namespace std;
void js(int a,int b,int num)
{
    num=0;int base=1;
    while(a>0){
        if(a&1) num+=base;
        base*=2;
        a/=2;
    }
    cout<<num+b;
}
int main()
{
    int a[2],z=0;
    int s=0;
    int num=0;
    int i=0;
    while(s==0)
    {
        cin>>a[i];
        i++;
        z++;
        if(z==2)
            s++;
    }
    js(a[1],a[0],num);
    return 0;
}

@C1WXY 调好了(


by luoyiwen @ 2024-09-11 14:35:03

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

by a_legend_cat @ 2024-09-12 22:44:29

#include <bits/stdc++.h>
using namespace std;
int add(int a, int b) {
  for(int i = 1; i <= b; i++)
    a += 1;
  return a;
}
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  printf("%d", add(a, b));
  return 0;
}

十分简单


by WC__ @ 2024-09-13 16:05:41

完了,a+b都不能直接看懂了


by C1WXY @ 2024-09-15 08:26:03

@chicken 谢谢大佬


|