数字检测 50分求调😣

#include<bits/stdc++.h>
using namespace std;
int n,sum = 0,mi = 1;
string s; 
bool b=0;
int a[51];  
char shu[1001]={'0','1','2','3','4','5','6','7','8','9'};
char ascm[1001]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int main(){
	cin >> n >> s;  
    if(n>=2&&n<=10){
        for(int i=0;i<s.length();i++){
            if(s[i]>='0'&&s[i]<=shu[n]){
                continue;
            }else{
                cout<<i<<" "<<s[i]<<endl;
                b=1;
            }
        }
        if(b==1) return 0;
    }else {
        for(int i=0;i<s.size();i++){
            if(s[i]>='0'&&s[i]<=ascm[n-11]){
                continue;
            }else{
                cout<<i+1<<' '<<s[i]<<endl;
                b=1;
            }
        }
        if(b==1) return 0;
    }
	for (int i = 0;i < s.size();i++)  {
		if (s[i] >= '0' && s[i] <= '9'){
			a[i] = s[i] - '0';
		}
		if (s[i] >= 'A' && s[i] <= 'F'){
			a[i] = s[i] + 10 - 'A';  
		}    
	}
	sum = a[s.size() - 1];
	for (int i = s.size() - 2;i >= 0;i--){
		mi *= n;
		sum += a[i] * mi; 
	}
	cout << sum;
}

哥你好像也没考虑小写字母

我加了之后还是50

在2~10里那个for循环里的判断应该是

if(s[i]>='0'&&s[i]<shu[n])

不能等于n
等于n就要进1了

这不一样吗

你的是s[i]<=shu[n]

我按你的改了

哦你刚刚那个if下面的else的输出第一个应该是i+1,不是i

image

那我再看看
你把改完的代码发一下

#include<bits/stdc++.h>
using namespace std;
int n,sum = 0,mi = 1;
string s; 
bool b=0;
int a[51];  
char shu[1001]={'0','1','2','3','4','5','6','7','8','9'};
char ascm[1001]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int main(){
	cin >> n >> s;  
    if(n>=2&&n<=10){
        for(int i=0;i<s.length();i++){
            if(s[i]>='0'&&s[i]<shu[n]){
                continue;
            }else{
                cout<<i+1<<" "<<s[i]<<endl;
                b=1;
            }
        }
        if(b==1) return 0;
    }else {
        for(int i=0;i<s.size();i++){
            if(s[i]>='0'&&s[i]<=ascm[n-11]){
                continue;
            }else{
                cout<<i+1<<' '<<s[i]<<endl;
                b=1;
            }
        }
        if(b==1) return 0;
    }
	for (int i = 0;i < s.size();i++)  {
		if (s[i] >= '0' && s[i] <= '9'){
			a[i] = s[i] - '0';
		}
		if (s[i] >= 'A' && s[i] <= 'F'){
			a[i] = s[i] + 10 - 'A';  
		}    
	}
	sum = a[s.size() - 1];
	for (int i = s.size() - 2;i >= 0;i--){
		mi *= n;
		sum += a[i] * mi; 
	}
	cout << sum;
}`预先格式化的文本`

倒数第2个for循环里的第二个if判断,也就是判断字母那个应该是

if(s[i]>='A'&&s[i]<='Z')

因为n<=35

image

int n;
string s,u="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int biry(int m,string s){
  int ans=0;
  for(int i=0;i<s.size();i++){
    char t=s[i];
    if(t>='0'&&t<='9')ans=ans*m+(t-'0');
    else ans=ans*m+(t-'A')+10;
  }
  return ans;
}
//主函数
  //输入
  vector<pair<int,char>> ero;
  for(int i=0;i<s.size();i++){
    bool flg=false;
    for(int j=0;j<n;j++){
      if(u[j]==s[i]){flg=true;break;}
    }
    if(!flg)ero.push_back(make_pair(i+1,s[i]));
  }

核心代码

@王朝民 提问请发到问题讨论区,发在常规的将会被删帖。