Code in C++ :
//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,a[MAX],sum;
vi v;
int solve(vi v){
int i,z,bor,x,y;
if(v.size()<=10){
ll num=0,p=1;
f(i,0,v.size()){
num+=v[i]*p;
p*=10;
}
if(num%7==0)
return 1;
else
return 0;
}
vi w;
z=v[0]*2;
x=z%10;z/=10;
bor=0;
f(i,1,v.size()){
if(i==1){
if(v[i]<x){
bor=1;
v[i]+=10;
}
w.pb(v[i]-x);
}
else if(i==2){
if(bor){
v[i]--;
bor=0;
}
if(v[i]<z){
v[i]+=10;
bor=1;
}
w.pb(v[i]-z);
}
else{
if(bor){
v[i]--;
bor=0;
}
if(v[i]<0){
v[i]+=10;
bor=1;
}
w.pb(v[i]);
}
}
return solve(w);
}
int check(int x){
int z,zz,i;
if(x==1)
return 1;
if(x==2)
if(v[0]%2==0)
return 1;
else
return 0;
if(x==3){
if(sum%3==0)
return 1;
else
return 0;
}
if(x==4){
if(v.size()==1){
if(v[0]%4==0)
return 1;
else
return 0;
}
z=v[0]+10*v[1];
if(z%4==0)
return 1;
else
return 0;
}
if(x==5)
if(v[0]==0 || v[0]==5)
return 1;
else
return 0;
if(x==6)
if(check(2) && check(3))
return 1;
else
return 0;
if(x==7){
if(solve(v))
return 1;
else
return 0;
}
if(x==8){
if(v.size()==1)
z=v[0];
else if(v.size()==2)
z=v[0]+10*v[1];
else
z=v[0]+10*v[1]+100*v[2];
if(z%8==0)
return 1;
else
return 0;
}
if(x==9){
if(sum%9==0)
return 1;
else
return 0;
}
if(x==10){
if(v[0]==0)
return 1;
else
return 0;
}
if(x==11){
zz=0;
f(i,0,v.size()){
if(i&1)
zz+=v[i];
else
zz-=v[i];
}
zz=abs(zz);
if(zz%11==0)
return 1;
else
return 0;
}
if(x==12)
if(check(4) && check(3))
return 1;
else
return 0;
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
si(t);
while(t--){
v.clear();
cin>>p;
n=p.size();
si(m);
f(i,0,m)
si(a[i]);
sum=0;
k=0;
rf(i,n-1,0){
v.pb(p[i]-'0');
sum+=v[k++];
}
c=0;
f(i,0,m){
if(!check(a[i]))
c=1;
}
if(c)
cout<<p<<" - Simple.";
else
cout<<p<<" - Wonderful.";
nl;
}
return 0;
}
Code in Java :
//\\__ hr1212 __//\\
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{
static int i,n,m,z,x,y,j,k,l,r,t;
static int a[];
static String s,p[],q;
static int MAX=1000010;
public static void main(String[] args) throws IOException{
InputReader in=new InputReader(System.in);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
t=Integer.parseInt(br.readLine());
for(j=0;j<t;j++){
s=br.readLine();
BigInteger b=new BigInteger(s);
p=br.readLine().split(" ");
z=0;
n=Integer.parseInt(p[0]);
for(i=1;i<=n;i++){
x=Integer.parseInt(p[i]);
if(b.mod(BigInteger.valueOf(x))!=BigInteger.ZERO){
z=1;
}
}
if(z==1)
System.out.println(b+" - Simple.");
else
System.out.println(b+" - Wonderful.");
}
out.close();
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar;
private int snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
No comments:
Post a Comment