aishwaryassr
BAN USERimport java.io.*;
import java.util.*;
public class Aish
{
//public static int count;
public static void generatesum(ArrayList<Integer>x,int total,int n)
{
int sum=0;
if(x.size()==n)
{
for(Integer y:x)
{
sum+=y;
}
if(sum==total)
System.out.println(x);
return;
}
for(int i=0;i<=total;i++)
{
x.add(i);
generatesum(x,total,n);
x.remove(x.size()-1);
}
}
public static void main(String[] args)
{
int total=15;
int n=3;
ArrayList<Integer> x=new ArrayList<Integer>();
generatesum(x,total,n);
}
}
Since this is just a string with parenthesis "( and )", just a normal counter should do:
import java.io.*;
import java.util.*;
import java.lang.Math;
public class New
{
public static void main(String[] args)
{
String s="(())))";
int i,count=0,res;
for(i=0;i<s.length();i++)
if(s.charAt(i)=='(')
count++;
else
count--;
res=Math.abs(count);
System.out.println(res);
}
}
import java.io.*;
import java.util.*;
public class Driv
{
public static void main(String[] args)
{
int i;
int max=0;
int sec=0;
String secmax="";
String firmax="";
List<String> x=new ArrayList<String>();
Scanner s=new Scanner(System.in);
for(i=0;i<7;i++)
x.add(s.next());
HashMap<String,Integer> hm=new HashMap<String,Integer>();
for(String str:x)
{
if(hm.containsKey(str))
{
hm.put(str,hm.get(str)+1);
}
else
hm.put(str,1);
}
for(Map.Entry<String,Integer> entry: hm.entrySet())
{
if(entry.getValue()>max)
{
sec=max;
secmax=firmax;
max=entry.getValue();
firmax=entry.getKey();
}
else if(entry.getValue()> sec)
{
sec=entry.getValue();
secmax=entry.getKey();
}
}
System.out.println("The second most repeating string is:"+secmax);
}
}
My code assumes that the id is a character,instead of a string. This can be extended to strings by using another map.
import java.io.*;
import java.util.*;
public class Log
{
public char id;
public int time;
public Log(char a, int b)
{
this.id = a;
this.time = b;
}
public static List<Character> findutil(Log[] logs,int m, int n)
{
int[] diff=new int[10];
int i;
int[] count=new int[26];
for(i=0;i<10;i++)
{
count[i]=1;
diff[i]=0;
}
for(int j=i;j<26;j++)
count[j]=1;
HashMap<Character,Log> hm= new HashMap<Character,Log>();
for(i=0;i<logs.length;i++)
{
if(hm.containsKey(logs[i].id))
{
Log temp=hm.get(logs[i].id);
diff[i]+=logs[i].time- temp.time;
if(diff[i]<=n)
count[logs[i].id-'a']++;
hm.put(logs[i].id,logs[i]);
}
else
{
hm.put(logs[i].id,logs[i]);
}
}
List<Character> x= new ArrayList<Character>();
for(i=0;i<10;i++)
if(count[i]==m)
{ //System.out.println("count[i]");
System.out.println(count[i]);
x.add(logs[i].id);
}
return x;
}
public static void main(String[] args)
{
int m=3,n=20;
Log[] x=new Log[10];
Scanner s=new Scanner(System.in);
x[0]=new Log('a',10);
x[1]=new Log('b',12);
x[2]=new Log('a',13);
x[3]=new Log('c',16);
x[4]=new Log('a',19);
x[5]=new Log('b',26);
x[6]=new Log('d',37);
x[7]=new Log('e',46);
x[8]=new Log('f',47);
x[9]=new Log('g',54);
List<Character> p = findutil(x,m,n);
System.out.println(p);
}
}
bool findpath(char ar[200][],int i, int j)
{
if(ar[i][j--]=='X' && ar[i][j++]=='X' && ar[i--][j]=='X' && ar[i++][j]=='X')
return false;
if(ar[i][j--]=='T' || ar[i][j++]=='T' || ar[i--][j]=='T' || ar[i++][j]=='T')
return true;
else
{
if(ar[i][j--]=="_")
findpath(ar,i,j--);
if(ar[i][j++]=="_")
findpath(ar,i,j++);
if(ar[i--][j]=="_")
findpath(ar,i--,j);
if(ar[i++][j]=="_")
findpath(ar,i++,j);
}
return false;
}
int main()
{
char ar[200][200];
int initr,endr;
for(int i=0;i<200;i++)
for(int j=0;j<200;j++)
cin>>ar[i][j];
for(i=0;i<N;i++)
for(j=0;j<N;j++)
if(ar[i][j]=='R')
{
initr=i;
endr=j;
break;
}
bool x=findpath(ar,initr,endr);
if(x == true)
cout<<"YES";
else
cout<<"NO";
return 0;
}
class Country
- aishwaryassr October 04, 2017{
String Name;
int countrycode; // to search by country
}
class RegionalCode
{
Country c;
Hashmap<RegionalCode,Trie>;
int regionalcode;
String RegionName;
}
class Trie
{
int number;
LinkedList<Integer>child;
}