Posted: Tue Dec 21, 2004 10:20 pm
I got ac.
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int find_per(char *bas[], char *nam, int ran){
for(int i = 1; i <= ran; i++){
if(strcmp(bas[i], nam) == 0)
return i;
}
return 0;
}
int main(){
int num_per, rec[11], giv[11],
mon_hav, num_rec, mon_giv,
nth_per,
i, j;
char *nam[11], *per = new(char);
while(scanf("%d", &num_per) == 1){
memset(rec, 0, sizeof(rec));
memset(giv, 0, sizeof(giv));
for(i = 1; i <= num_per; i++){
nam[i] = new(char);
scanf("%s", nam[i]);
}
for(i = 1; i <= num_per; i++){
mon_giv = 0;
scanf("%s %d %d", per, &mon_hav, &num_rec);
nth_per = find_per(nam, per, num_per);
if(num_rec != 0){
mon_giv = mon_hav / num_rec;
giv[nth_per] = mon_giv * num_rec;
}
for(j = 1; j <= num_rec; j++){
scanf("%s", per);
rec[find_per(nam, per, num_per)] += mon_giv;
}
}
for(i = 1; i <= num_per; i++)
printf("%s %d\n", nam[i], rec[i] - giv[i]);
printf("\n");
}
return 0;
}
Code: Select all
#include<iostream>
using namespace std;
short n;
struct gift
{char cad[13];
int spend;
int rec;
gift *next;
};
char c[13];
int i,d,g,t,p,k;
gift *cab,*grupo,*aux;
int main()
{while(cin>>n)
{cab=new gift;
cin>>cab->cad;
grupo=cab;
grupo->rec=0;
for(i=1;i<n;i++)
{aux=new gift;
cin>>aux->cad;
aux->rec=0;
grupo->next=aux;
grupo=grupo->next;
}
grupo=cab;
for(i=0;i<n;i++)
{cin>>c>>d>>g;
grupo=cab;
for(;;)
{k=0;
while(c[k]!='\0'&&c[k]==grupo->cad[k])
k++;
if(c[k]==grupo->cad[k])
break;
grupo=grupo->next;
}
grupo->spend=d;
t=(d/g);
for(p=0;p<g;p++)
{cin>>c;
grupo=cab;
for(;;)
{k=0;
while(c[k]!='\0'&&c[k]==grupo->cad[k])
k++;
if(c[k]==grupo->cad[k])
break;
grupo=grupo->next;
}
grupo->rec+=t;
}
}
grupo=cab;
p=0;
do
{
i=0;
while(grupo->cad[i]!='\0')
{cout<<grupo->cad[i];
i++;
}
cout<<" "<<grupo->spend-grupo->rec<<endl;
grupo=grupo->next;
p++;
}while(p<n);
}
return 0;
}
Code: Select all
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
int main(void)
{
while( !cin.eof() )
{
int n;
vector<string> names;
map< string, int > give, got;
cin >> n;
names.resize(n);
for( int i = 0; i < n; ++i )
{
cin >> names[i];
give[names[i]] = got[names[i]] = 0;
}
for ( int i = 0; i < n; ++i )
{
string ime, tokom;
int st, to;
cin >> ime >> st >> to;
for( int j = to; j; --j )
{
cin >> tokom;
got[tokom] += st / to;
give[ime] += st / to;
}
}
for( int i = 0; i < n; ++i )
cout << names[i] << " " << got[names[i]] - give[names[i]] << endl;
if( !cin.eof() )
cout << endl;
}
return 0;
}
Code: Select all
/* begin_of_source_code */
/* @JUDGE_ID: 38154WT 119 Java */
import java.io.*;
import java.util.*;
class Main
{
public static void main(String[] args) throws IOException
{
class Person
{
private String per_strName;
private int per_iMoney;
public Person()
{
per_strName = "yo";
per_iMoney = 0;
}
public Person(String strName, int iMoney)
{
per_strName = strName;
per_iMoney = iMoney;
}
public String getName()
{
return per_strName;
}
public void setName(String strName)
{
per_strName = strName;
}
public int getMoney()
{
return per_iMoney;
}
public void setMoney(int iMoney)
{
per_iMoney = iMoney;
}
public void addMoney(int iMoney)
{
per_iMoney = per_iMoney + iMoney;
}
public void subtractMoney(int iMoney)
{
per_iMoney = per_iMoney - iMoney;
}
}//end class person
String input;
String strName;
String giver;
String luckyone;
int money = 0;
int sharedPerPerson = 0;
int retained = 0;
int countpresents = 0;
int iHowMany = 0;
int step = 1;
int count = 0;
StringTokenizer getter;
//boolean bFirstRun = true;
boolean bDone = false;
Person[] allPeople = new Person[50];;
while((input = readLine(255)) !=null)
{
getter = new StringTokenizer(input);
if (step == 1)
{
iHowMany = Integer.parseInt(getter.nextToken());
}
if (step == 2)
{
//System.out.println("getting all the names");
for (int i = 0; i < iHowMany; i++)
{
strName = getter.nextToken();
Person x = new Person(strName, 0);
allPeople[i] = x;
}
}
if (step == 3)
{
//for each person, read new line and parse
for (int i = 0; i <= iHowMany; i++)
{
getter = new StringTokenizer(input);
count = getter.countTokens();
giver = getter.nextToken();
money = Integer.parseInt(getter.nextToken());
; countpresents = Integer.parseInt(getter.nextToken());
if ((money != 0) && (countpresents != 0))
{
sharedPerPerson = money/countpresents;
retained = money%countpresents;
}
else
{
sharedPerPerson = 0;
retained = 0;
}
//for each name who is getting something
for (int j = 0; j < countpresents; j++)
{
luckyone = getter.nextToken();
String output = luckyone + " gets " + sharedPerPerson;
output += " by " + giver;
//iterate the array and check if have right person
for (int index = 0; index < iHowMany; index++)
{
if (allPeople[index].getName().equals(giver))
{
allPeople[index].subtractMoney(sharedPerPerson);
//System.out.println(allPeople[index].getName() + " now has $" + allPeople[index].getMoney());
}
if (allPeople[index].getName().equals(luckyone))
{
allPeople[index].addMoney(sharedPerPerson);
//System.out.println(allPeople[index].getName() + " now has $" + allPeople[index].getMoney());
}
}//iterating array
}//end for each name getting something loop
if (i < (iHowMany - 1))//read new line EXCEPT last time through
{
input = readLine(255);
}
}//end for each person total loop
//Output
for (int a = 0; a < iHowMany; a++)
{
String fun = allPeople[a].getName() + " ";
fun += allPeople[a].getMoney();
System.out.println(fun);
}
System.out.println();
//reset everything
strName = "";
giver = "";;
luckyone = "";;
money = 0;
sharedPerPerson = 0;
retained = 0;
countpresents = 0;
iHowMany = 0;
count = 0;
allPeople = new Person[50];
}//end if step 3 statemet
if (step == 3)
{
step = 1;
}
else
{
step++;
}
}
}//end main()
static String readLine(int maxLg) throws IOException {
byte[] lin = new byte[maxLg];
int lg = 0, car = -1;
while(lg < maxLg) {
car = System.in.read();
if(car<0 || car=='\n') break;
lin[lg++] += car;
}
if(car<0 && lg==0) return null;
return new String(lin, 0, lg);
}//end read line
}//end class
/* end_of_source_code */
Code: Select all
for(i=0; i<n; i++)
{
sum=0;
for(j=0; j<n; j++)
{
sum+=matrix[j][i];
if(matrix[j][i]!=0)
{
zerocounter++;
}
}
cout<<p[i].name<<" ";
if(zerocounter==0)
{
cout<<0;
}
else
{
cout<<sum-capital[i];
}
cout<<endl;
}