Vaccine code

Practice

Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD

DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

PREREQUISITES:

Math .

PROBLEM:

All peoples are curious to get vaccinate but for getting vaccinate first everyone has to complete his/her registration online . when they complete their online registration one security code is generated. if the generated security code is multiple of 3 then he is valid for vaccination otherwise not valid . you have to find who is valid or who is not valid.

EXPLANATION:

You have given string you just have to find out wether the given number is multiple of 3 or not
for this we have to first convert given string into a number and we will add individual digits if the addition is multiple of 3 then print valid else not valid
for example
if the given digit is 345
addition of these digits =12 and it is multiple of 3 hence the output is valid

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
string s;
long long int hp=0;
cin>>s;
for(int i=0;i<s.size();i++){
hp+=s[i]-‘0’;
}
if(hp%3==0){
cout<<“valid”;
}
else{
cout<<“not valid”;
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution
   #include<bits/stdc++.h>

using namespace std;
void testcase()
{
string s;
long long int hp=0;
cin>>s;
for(int i=0;i<s.size();i++){
hp+=s[i]-‘0’;
}
if(hp%3==0){
cout<<“valid”;
}
else{
cout<<“not valid”;
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

indent whole code by 4 spaces