topic
Title link
Problem-solving ideas
There is a spj code in the background, which can verify the output data of students and pass if it meets the conditions.
Attached with spj code
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
bool check(string &s)
{
if(()>10)
return false;
if(()=='0')
return false;
for(char &c:s)
{
if(c=='-')
return false;
else if(!isdigit(c))
return false;
}
return true;
}
int main(void)
{
// Remember to rename it
ifstream in,out,user_out;
("input");
("output");
user_out.open("user_output");
string s;
long long sum=0,res;
int n,m,i;
in>>n>>m;
for(i=1;i<=n;++i)
{
if(!(user_out>>s))
return 1;
if(!check(s))
return 1;
res=stoll(s);
sum+=res;
}
if(sum!=m)
return 1;
if(user_out>>s)
return 1;
return 0;
}
Code
#include <iostream>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
(0);
int n,m,i;
cin>>n>>m;
for(i=1;i<n;++i)
cout<<"1 ";
cout<<m-n+1;
return 0;
}
import ;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner();
int n=(),m=(),i;
int[] a=new int[n+5];
for(i=1;i<n;++i)
a[i]=1;
a[n]=m-n+1;
for(i=1;i<=n;++i)
(a[i]+" ");
}
}
n,m=map(int,input().split())
# print('1 '*(n-1)+str(m-n+1))
a=[1]*(n-1)
(m-n+1)
print(' '.join(map(str,a)))
Algorithm and complexity
- Algorithm: None.
- Time complexity:\(\mathcal{O}(n)\) 。
- Space complexity:\(\mathcal{O}(n)\). This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank.