Beruflich Dokumente
Kultur Dokumente
#include <stdio.h>
#include <stdlib.h>
#define MAX 25
int table_loc;
int value;
} block;
block *table[MAX];
block *b;
while(a->above != NULL) {
b = a->above;
a->above = NULL;
b->below = NULL;
b->table_loc = b->value;
table[b->value] = b;
a = b;
}
}
return a;
top_b->above = a;
a->below = top_b;
while(a != NULL) {
a->table_loc = table_loc;
a = a->above;
void print_table(int n) {
block *a;
int i;
printf("%d:", i);
printf("\n");
int main() {
int n, i, v;
block *blocks[MAX];
Si(n);
blocks[i]->above = NULL;
blocks[i]->below = NULL;
blocks[i]->table_loc = i;
blocks[i]->value = i;
while(1) {
Ss(verb);
Si(v);
a = blocks[v];
Ss(prep);
Si(v);
b = blocks[v];
/* When verb is `move`, put back that are above the object
`a`. */
stack(a, b);
print_table(n);
free(blocks[i]);
return 0;
#include <stdio.h>
#include <string.h>
#define s 25
int block[s][s];
int result[s];
int n;
for(p;p<result[row];p++)
{
val=block[row][p];
block[val][result[val]]=block[row][p];
result[val]++;
}
}
int main()
{
char input[50],x[10],y[10];
int i,j,a,b,pos1,pos2,p;
//freopen("b.in","r",stdin);
while((scanf("%d\n",&n))==1)
{
/*initialize*/
for(i=0;i<n;i++)
{
block[i][0]=i;
result[i]=1;
}
while(gets(input))
{
sscanf(input,"%s %d %s %d\n",&x,&a,&y,&b);
if(strcmp(x,"quit")==0)
break;
i=find(a,pos1);
j=find(b,pos2);
if(i==j)
continue;
if(strcmp(x,"move")==0)
{
return_to_initial(i,pos1+1);
result[i]=pos1;
if(strcmp(y,"onto")==0)
{
return_to_initial(j,pos2+1);
result[j]=pos2+1;
}
block[j][result[j]++]=a;
}
else if(strcmp(x,"pile")==0)
{
if(strcmp(y,"onto")==0)
{
return_to_initial(j,pos2+1);
result[j]=pos2+1;
}
for(p=pos1;p<result[i];p++)
block[j][result[j]++]=block[i][p];
result[i]=pos1;
}
}
for(i=0;i<n;i++)
{
printf("%d:",i);
if(!result[i])
{
printf("\n");
continue;
}
for(j=0;j<result[i];j++)
printf(" %d",block[i][j]);
printf("\n");
}
}
return 0;
}
import java.util.Scanner;
public class blockproblem {
int[] cariStack(int n,String str[],String cari){
int x=-1,i=0;
int indx=-1;
int hasil[]=new int[2];
do{
if(str[i]!=null){
x=str[i].indexOf(cari);
}
if(x>=0) indx=i;
i++;
}while((x<0)&&(i<n));
hasil[0]=indx;
hasil[1]=x;
return hasil;
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
blockproblem bp=new blockproblem();
int n=s.nextInt();
String st[]=new String[n];
for (int i = 0; i < n; i++) {
st[i]=String.valueOf(i);
}
String cmd="",src,pos,des;
while(!(cmd.equalsIgnoreCase("quit"))){
cmd=s.next();
if(!(cmd.equalsIgnoreCase("quit"))){
src=s.next();
pos=s.next();
des=s.next();
if(cmd.equalsIgnoreCase("move")){
if(pos.equalsIgnoreCase("onto")){
int [] urut=bp.cariStack(n,st,src);
int [] urutdes=bp.cariStack(n,st,des);
if(urut[0]>=0){
if(st[urutdes[0]]==null) st[urutdes[0]] = src;
else st[urutdes[0]] += src;
if(st[urut[0]].length()==src.length()) {
st[urut[0]]=null;
}else if(urut[1]==0){
st[urut[0]]=st[urut[0]].substring(1, st[urut[0]].length());
}else if(urut[1]==st[urut[0]].length()-1){
st[urut[0]]=st[urut[0]].substring(0, st[urut[0]].length()-1);
}else{
st[urut[0]]=st[urut[0]].substring(0, urut[1]-1)
+ st[urut[0]].substring(urut[1]+1, st[urut[0]].length());
}
}
}else if(pos.equalsIgnoreCase("over")) {
int [] urut=bp.cariStack(n,st,src);
int [] urutdes=bp.cariStack(n,st,des);
if(urut[0]>=0){
if(st[urutdes[0]+1]==null) st[urutdes[0]+1] = src;
else st[urutdes[0] + 1] += src;
if(st[urut[0]].length()==src.length()) {
st[urut[0]]=null;
}else if(urut[1]==0){
st[urut[0]]=st[urut[0]].substring(1, st[urut[0]].length());
}else if(urut[1]==st[urut[0]].length()-1){
st[urut[0]]=st[urut[0]].substring(0, st[urut[0]].length()-1);
}else{
st[urut[0]]=st[urut[0]].substring(0, urut[1]-1)
+ st[urut[0]].substring(urut[1]+1, st[urut[0]].length());
}
}
}
}else if(cmd.equalsIgnoreCase("pile")){
if(pos.equalsIgnoreCase("onto")){
if(Integer.parseInt(des)<n){
int [] urut=bp.cariStack(n,st,src);
if(urut[0]>=0){
if(st[Integer.parseInt(des)]==null) st[Integer.parseInt(des)] = st[urut[0]];
else st[Integer.parseInt(des)] += st[urut[0]];
st[urut[0]]=null;
}
}
}else if(pos.equalsIgnoreCase("over")) {
if(Integer.parseInt(des)<n-1){
int [] urut=bp.cariStack(n,st,src);
if(urut[0]>=0){
if(st[Integer.parseInt(des)+1]==null) st[Integer.parseInt(des) + 1] = st[urut[0]];
else st[Integer.parseInt(des) + 1] += st[urut[0]];
st[urut[0]]=null;
}
}
}
}
}
}
for (int i = 0; i < st.length; i++) {
System.out.println(i+":"+st[i]);
}
}
}
import java.awt.Point;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Sanchit M. Bhatnagar
* @see http://uhunt.felix-halim.net/id/74004
*
*/
public class P101 {
// System.out.println(Arrays.deepToString(blocks));
while (sc.hasNext()) {
String t = sc.next();
if (t.equals("quit")) {
break;
} else {
int a = sc.nextInt();
String x = sc.next();
int b = sc.nextInt();
if (a == b)
continue;
if (posA.x == posB.x)
continue;
if (t.equals("move")) {
moveBack(posA, blocks);
if (x.equals("onto")) {
moveBack(posB, blocks);
blocks[posA.x].remove(posA.y);
blocks[posB.x].add(a);
} else {
blocks[posA.x].remove(posA.y);
blocks[posB.x].add(a);
}
} else if (t.equals("pile")) {
if (x.equals("onto")) {
moveBack(posB, blocks);
int removed = 0;
int tSize = blocks[posA.x].size();
for (int i = posA.y; i < tSize; i++) {
blocks[posB.x].add(blocks[posA.x].remove(i - removed));
removed++;
}
} else {
int removed = 0;
int tSize = blocks[posA.x].size();
for (int i = posA.y; i < tSize; i++) {
blocks[posB.x].add(blocks[posA.x].remove(i - removed));
removed++;
}
}
}
}
// System.out.println(Arrays.deepToString(blocks));
}
// System.out.println(Arrays.deepToString(blocks));
Cost Cutting
#include<stdio.h>
int main()
{
int a,b,c,d,ans,j;
while(scanf("%d",&d)==1)
{
for(j=1;j<=d;j++)
{
scanf("%d%d%d",&a,&b,&c);
if(a>b && b>c || a<b && b<c)
ans=b;
if(a>c && c>b || a<c && c<b)
ans=c;
if(b>a && a>c || b<a && a<c)
ans=a;
printf("Case %d: %d\n",j,ans);
}
}
return 0;
}
Automatic Answer
#include<stdio.h>
int main()
{
int t,i,n,ans,a,m;
while(scanf("%d",&t)==1)
{
i=1;
while(i<=t)
{
scanf("%d",&n);
a=n*315+36962;
m=a/10;
ans=m%10;
if(ans<0)
ans=ans/(-1);
printf("%d\n",ans);
i++;
}
}
return 0;
}
Tex Quotes
#include<stdio.h>
#include<string.h>
int main()
{
char s[100000];
long i,l,p=0;
while(gets(s))
{
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='"')
{
p=p+1;
if(p%2==1)
printf("``");
else
printf("''");
}
else
printf("%c",s[i]);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main ()
{
int testCase; scanf ("%d", &testCase);
while ( testCase-- )
{
char a [10]; scanf ("%s", a);
return 0;
}
List of Conquests
#include<stdio.h>
#include<string.h>
int main()
{
int a,i,j,k;
char cn[2001][30],ld[70];
while(scanf("%d",&a)==1)
{
int count[2001]= {0};
for(i=0; i<a; i++)
{
scanf("%s",cn[i]);
gets(ld);
}
for(i=0; i<a; i++)
for(j=i+1; j<a; j++)
if(strcmp(cn[i],cn[j])==0)
{
count[i]++;
cn[j][0]='\0';
}
for(i=0; i<a-1; i++)
{
for(j=i+1; j<a; j++)
{
if(cn[j][0]=='\0')continue;
if(strcmp(cn[i],cn[j])>0)
{
strcpy(ld,cn[i]);
strcpy(cn[i],cn[j]);
strcpy(cn[j],ld);
k=count[i];
count[i]=count[j];
count[j]=k;
}
}
}
for(i=0; i<a; i++)
{
if(cn[i][0]!='\0')
printf("%s %d\n",cn[i],count[i]+1);
}
}
return 0;
}
One-Two-Three
Source Code:
/**
* @link https://quickgrid.wordpress.com
*/
#include<stdio.h>
#define O 111
#define N 110
#define E 101
int main(){
register unsigned n;
scanf("%u", &n);
while (n--){
scanf("%s", s);
if (s[3]){
printf("3\n");
}else{
unsigned s0 = s[0];
unsigned s1 = s[1];
unsigned s2 = s[2];
printf("1\n");
else
printf("2\n");
return 0;
}
#include <stdio.h>
/*Time : 0.004s*/
int main(){
int i,t,len,cnt;
char str[5],one[]={"one"};
scanf("%d",&t);
while(t--){
scanf("%s",str);
for( len = 0; str[len]; len++);
cnt = 0;
if(len == 5)
printf("3\n");
else{
for( i = 0; i < len; i++){
if( one[i] == str[i]){
cnt++;
}
}
if( cnt >= 2)
printf("1\n");
else
printf("2\n");
}
}
return 0;
}
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main (String args[]) {
Scanner scanner = new Scanner(System.in);
int sum[] = new int[1010];
import
java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;
/**
*
* @author ahani
*/
public class Main {
public static int NumberBlocks;
public static Stack<Integer> Blocks[];
public static int Position[];
public static String Line;
public static int A, B;
//}
Line = "";
while(!(Line = Input.readLine()).equals("quit")) {
StringTokenizer token = new
StringTokenizer(Line);
String First = token.nextToken();
A = Integer.parseInt(token.nextToken());
String Second = token.nextToken();
B = Integer.parseInt(token.nextToken());
Blocks[Position[Second]].push(Blocks[Position[First]].pop());
Position[First] = Position[Second];
}
public static void PileOnto(int First, int Second) {
ClearAbove(Second);
PileOver(First, Second);
}
public static void PileOver(int First, int Second) {
Stack<Integer> Pile = new Stack<Integer>();
while(Blocks[Position[First]].peek() != First) {
Pile.push(Blocks[Position[First]].pop());
}
Pile.push(Blocks[Position[First]].pop());
while(!Pile.isEmpty()) {
int Tmp = Pile.pop();
Blocks[Position[Second]].push(Tmp);
Position[Tmp] = Position[Second];
}
}
public static void ClearAbove(int Block) {
while(Blocks[Position[Block]].peek() != Block) {
Intial(Blocks[Position[Block]].pop());
}
}
public static void Intial(int Block) {
while(!Blocks[Block].isEmpty()) {
Intial(Blocks[Block].pop());
}
Blocks[Block].push(Block);
Position[Block] = Block;
}
public static String Solve(int Index) {
String Result = "";
while(!Blocks[Index].isEmpty()) Result = " " +
Blocks[Index].pop() + Result;
Result = Index + ":" + Result;
return Result;
}