Getting Started with algorithms _ Arrays and strings

Source: Internet
Author: User

Vertical problem:

#include <stdio.h>
#include <string.h>
int main (void)
{
int count = 0;
Char s[20],buf[99];
scanf ("%s", s);
int ABC, DE;
for (abc=111;abc<=999;abc++)
for (de=11;de<=99;de++) {
int x;
x = abc* (de%10);
int y;
y=abc* (DE/10);
int z;
Z=abc*de;
sprintf (buf, "%d%d%d%d%d", ABC, DE, X, y, z);
int OK = 1;
int i;
For (I=0;i<strlen (BUF); i++)
if (STRCHR (S, buf[i]) = = NULL)
ok=0;
if (OK) {
printf ("<%d>\n", ++count);
printf ("%5d\nx%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n", abc,de,x,y,z);
}
}
printf ("The number of solutions =%d\n", count);
return 0;
}

TeX

#include <stdio.h>
int main (void)
{
int c,q=1;
while ((c = GetChar ())! = EOF) {
if (c = = ' "') {
printf ("%s", Q? "“" : "”");
Q =!q;
}
Else
printf ("%c", c);
}
return 0;
}
This program converts the quotation marks in English into Chinese quotation marks.

Wertyu:

#include <stdio.h>
Char s[] = "' 1234567890-=qwertyuiop[]\\asdfghjkl; ' Zxcvbnm,./";
int main (void)
{
int I, C;
while ((C=getchar ())! = EOF) {
For (I=1;s[i] && s[i]! = C; i++)
;
if (S[i])
Putchar (S[i-1]);
Else
Putchar (c);
}
return 0;
}

Palindrome Number:

#include <stdio.h>
#include <string.h>
#include <ctype.h>
Const char* REV = "A 3 HIL JM O 2tuvwxy51se Z 8";
Const char* msg[] = {"Not a palindrome", "a regular palindrome", "a mirrored string", "A Mirrored palindrome"};
Char r (Char ch) {
if (Isalpha (CH))
Return rev[ch-' A '];
Return rev[ch-' 0 ' + 25];
}


int main (void)
{
Char s[30];
while (scanf ("%s", s) = = 1) {
int len = strlen (s);
int p=1, m = 1;
int i;
for (i=0; i< (len+1)/2;i++) {
if (s[i]! = S[len-1-i])
p = 0;
if (R (s[i])! = S[len-1-i])
m = 0;
}
printf ("%s--is%s.\n\n", S, Msg[m*2+p]);
}
return 0;
}

Guess number game:

#include <stdio.h>
#define MAXN 1010


int main (void)
{
int n, A[MAXN], B[MAXN];
int kase = 0;
while (scanf ("%d", &n) = = 1 && N)
{
printf ("Game%d:\n", ++kase);
int i;
for (i=0;i<n;i++)
scanf ("%d", &a[i]);
for (;;) {
int A = 0, B = 0;
int i;
for (i=0;i<n;i++) {
scanf ("%d", &b[i]);
if (a[i] = = B[i])
a++;
}
if (b[0] = = 0)
Break
int D;
for (d=1; d<=9; d++) {
int c1=0,c2=0;
int i;
for (i=0; i<= N; i++) {
if (a[i] = = d)
c1++;
if (b[i] = = d)
c2++;
}
if (C1 < C2)
B + = C1;
Else
B + = C2;
}
printf ("(%d,%d) \ n", A, b-a);
}
}
return 0;
}

Raw Narimoto:

#include <stdio.h>
#include <string.h>
#define MAXN 100005
int ANS[MAXN];


int main (void)
{
int T, n;
memset (ans, 0, sizeof (ans));
int m;
for (m=1;m<maxn;m++) {
int x = m, y = m;
while (x>0) {
Y + = x%10;
x/= 10;
}
if (ans[y] = = 0 | | m < ans[y])
Ans[y] = m;
}
scanf ("%d", &t);
while (t--) {
scanf ("%d", &n);
printf ("%d\n", Ans[n]);
}
return 0;
}

Ring sequence:

#include <stdio.h>
#include <string.h>
#define MAXN 105


int less (const char *s, int p, int q) {
int n = strlen (s);
int i;
for (i=0;i<n;i++)
if (s[(p+i)%n]! = s[(q+i)%n])
Return s[(p+i)%n] < s[(q+i)%n];
return 0;
}
int main (void)
{
int T;
Char S[MAXN];
scanf ("%d", &t);
while (t--) {
scanf ("%s", s);
int ans = 0;
int n = strlen (s);
int i;
for (i=1;i<n;i++)
if (less (s, I, ans))
ans = i;
for (i=0;i<n;i++)
Putchar (s[(I+ans)%n]);
Putchar (' \ n ');
}
return 0;
}


This is in accordance with the introduction of the algorithm competition in the third chapter of the problem, mainly related to arrays and strings, the individual feel that there is a certain difficulty, recorded in the blog, for future reference.

Getting Started with algorithms _ Arrays and strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.