update
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
const int BITS_IN_BYTE = 8;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
string text = get_string("Text: ");
|
||||
|
||||
// Loop over every character
|
||||
|
||||
int i = 0;
|
||||
int l = 0;
|
||||
double rest = 0;
|
||||
double zahl;
|
||||
int len = 0;
|
||||
int bi;
|
||||
int n = 0;
|
||||
int m = 0;
|
||||
|
||||
for (i = 0, len = strlen(text); i < len; i++)
|
||||
{
|
||||
zahl = text[i];
|
||||
bi = 0;
|
||||
for (l = 0; l < BITS_IN_BYTE; l++)
|
||||
{
|
||||
zahl = (zahl - (rest * pow(10, -1))) / 2.0 ;
|
||||
rest = (zahl - floor(zahl)) * 10;
|
||||
|
||||
if (rest > 0)
|
||||
{
|
||||
bi = bi + pow(10, l);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (bi >= 1000000 && bi <= 1111111)
|
||||
{
|
||||
char test[bi];
|
||||
sprintf(test, "0%d", bi);
|
||||
//printf("%s",test);
|
||||
for (n = 0, m = strlen(test); n < m; n++)
|
||||
{
|
||||
if (test[n] == 48)
|
||||
{
|
||||
// Dark emoji
|
||||
printf("\U000026AB");
|
||||
}
|
||||
else if (test[n] == 49)
|
||||
{
|
||||
// Light emoji
|
||||
printf("\U0001F7E1");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bi >= 100000 && bi <= 111111)
|
||||
{
|
||||
char test[bi];
|
||||
sprintf(test, "00%d", bi);
|
||||
//printf("%s",test);
|
||||
for (n = 0, m = strlen(test); n < m; n++)
|
||||
{
|
||||
if (test[n] == 48)
|
||||
{
|
||||
// Dark emoji
|
||||
printf("\U000026AB");
|
||||
}
|
||||
else if (test[n] == 49)
|
||||
{
|
||||
// Light emoji
|
||||
printf("\U0001F7E1");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Get Text
|
||||
string text = get_string("Text: ");
|
||||
|
||||
// Letter, word, sentence count
|
||||
double lettercount = 0;
|
||||
double wordcount = 1;
|
||||
double sentencecount = 0;
|
||||
|
||||
for (int i = 0, len = strlen(text); i < len; i++)
|
||||
{
|
||||
if ((text[i] >= 65 && text[i] <= 90) || (text[i] >= 97 && text[i] <= 122))
|
||||
{
|
||||
lettercount += 1;
|
||||
}
|
||||
else if (text[i] == 32)
|
||||
{
|
||||
wordcount += 1;
|
||||
}
|
||||
else if (text[i] == 33 || text[i] == 63 || text[i] == 46)
|
||||
{
|
||||
sentencecount += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate Index
|
||||
double L = lettercount / wordcount * 100.0;
|
||||
double S = sentencecount / wordcount * 100.0;
|
||||
double index = 0.0588 * L - 0.296 * S - 15.8;
|
||||
|
||||
// Print conditions
|
||||
if (index <= 1)
|
||||
{
|
||||
printf("Before Grade 1\n");
|
||||
}
|
||||
else if (index >= 16)
|
||||
{
|
||||
printf("Grade 16+\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Grade %i\n", (int) round(index));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#include <ctype.h>
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// Points assigned to each letter of the alphabet
|
||||
int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
|
||||
|
||||
int compute_score(string word);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Get input words from both players
|
||||
string word1 = get_string("Player 1: ");
|
||||
string word2 = get_string("Player 2: ");
|
||||
|
||||
// Score both words
|
||||
int score1 = compute_score(word1);
|
||||
int score2 = compute_score(word2);
|
||||
|
||||
// TODO: Print the winner
|
||||
if (score1 > score2)
|
||||
{
|
||||
printf("Player 1 wins!");
|
||||
}
|
||||
else if (score1 < score2)
|
||||
{
|
||||
printf("Player 2 wins!");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Tie!");
|
||||
}
|
||||
}
|
||||
|
||||
int compute_score(string word)
|
||||
{
|
||||
// TODO: Compute and return score for string
|
||||
int score = 0;
|
||||
|
||||
for (int i = 0, len = strlen(word); i < len; i++)
|
||||
{
|
||||
if (isupper(word[i]))
|
||||
{
|
||||
score += POINTS[word[i] - 'A'];
|
||||
}
|
||||
else if (islower(word[i]))
|
||||
{
|
||||
score += POINTS[word[i] - 'a'];
|
||||
}
|
||||
}
|
||||
return score;
|
||||
}
|
||||
Reference in New Issue
Block a user